Recently, when trying to compile java programs from the command prompt, I get this error:
Error: Cannot find or load main class com.sun.tools.javac.Main
I have the latest versions of the JDK and JRE, and I still get the error.
Here is what I type in the command line:
C:\Java_Source_Codes>javac hi.java
Can anyone help?
(Here is my java code)
public class hi{
public static void main(String[] args){
System.out.println("hello, world!");
}
}
You have a number of issues, Kumar mentioned the compilation issue, but that’s not the immediate problem that’s stopping you.
You have
JAVA_HOMEset to a Java Runtime environment, but are findingjavacon the systemPATH. When this happens, you can calljavacfrom the command line, but whenjavacdetects theJAVA_HOMEenvironmental variable, it loads its libraries from a directory that doesn’t include the “java tools”,tools.jar. The contents of “java tools” includes the classes that implement the compiler.You probably have
JAVA_HOMEset to something like/some/path/here/jre. Assuming that thejredirectory is the embedded JRE shipped with your JDK, you probably should have set theJAVA_HOMEto/some/path/here.