简体   繁体   中英

unable to compile java program from command prompt in Windows 7

I have set Path and ClassPath environment variables. But still I am unable to compile my HelloWorld.java program from command prompt. Please help me compile and run java program from command prompt

CLASSPATH C:\Program Files\Java\jre6\lib

Path C:\Program Files\Java\jre6\bin\

You need to add JDK's directory to your path variable (not your JRE's path as you are actually doing it). JDK is usually in:

C:\Program Files\Java\jdk1.6.0_xx\bin\

Where xx stands for update number you have installed. Then just compile HelloWorld by using:

C:\Your\dir\where\HelloWorld\Is\>javac HelloWorld.java

In case you don't have JDK installed and you have only JRE installed, you won't be able to compile anything. You will need to download and install JDK properly to do Java Development in general (including compiling stuff).

You need a JDK to compile classes rather than a JRE. The JRE is used for running Java applications (the JDK can also do this, but you cannot distribute the JDK).

When you have installed a JDK, ensure that the JDKs bin directory is on your path. You can then compile your Java classes using the javac.exe command.

You could try writing cd C:\examples\ch01\ATM then press enter and that will change your directory. This allows you to write for example java ATMCaseStudy , then press enter. This should work if you placed your directory in C with your JDK in the same place.

PATH must be like

C:\Program Files\Java\jdk1.6.0\bin (This is on my system)

That is must point to JDK's bin not the jre's bin.Hope this helps.

You should also have your current directory in the CLASSPATH.

set CLASSPATH=.;C:\Program Files\Java\jre6\lib;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM