'How to reset the system variable: CLASSPATH for JAVA?
I am using Windows 7 and I modified the CLASSPATH and now, in the cmd window, my JAVA cannot work properly: it can compile classes properly, but when I try to run it using:"java CLASS"
, the system always says "Could not find or load main class"
The reset 2 system variables related to Java are:
- JAVA_HOME:
C:\Program Files\Java\jdk1.8.0_31
Path:
C:\Program Files\Java\jdk1.8.0_31\bin
CLASSPATH:
.;C:\Program Files\Java\jdk1.8.0_31\lib
(Updated version, still not working...)
Now, how could I reset my CLASSPATH?
My test code:
public class a {
public static void main(String[] args){
System.out.println("abc");
}
}
Solution 1:[1]
Use Your CLASSPATH
.;c:\Program Files\Java\jdk1.7.0_05\lib
Use ".;" . is refer to this and will find your class.
Your JAVA_HOME
c:\Program Files\Java\jdk1.7.0_05
and Your Path
c:\Program Files\Java\jdk1.7.0_05\bin;
Use this ... this is working fine for me.
Solution 2:[2]
You have to set path for your java Follow these steps:
1- Go to My computer
2- Properties
3- Advanced System Settings
4- Environment Variables
5- Select path in the 2nd LOWER LIST BOX
6- click on edit
Now first go to c:program files/java/jdk1.*/bin/ and copy this path at the end of your path
PATH: c://whatever/whatever APPEND: c://whatever/whatever***;//c://program files/java/jdk/bin***
Solution 3:[3]
You set your JAVA_HOME
incorrectly. The JAVA_HOME
home always should be like this -
JAVA_HOME: C:\Program Files\Java\jdk1.8.0_31;
Note: the JAVA_HOME
is set up to just before bin
directory.
I think modifying the JAVA_HOME
like this would solve your problem. The PATH
added here seems OK.
Solution 4:[4]
On windows. Worked for me.put in terminal "set CLASSPATH=" And my java program start executed in command prompt .
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | MILIND |
Solution 2 | Archit Dwivedi |
Solution 3 | Razib |
Solution 4 |