I have followed steps on Head First Java book to create jar file, everything worked well.
Now i need to read/open that jar file to run the classes.
I have a classes file on top of bin folder.
When i run this code, it cant find jar file.
C:\Program Files\Java\jdk1.6.0_21\bin> java -jar -classpath ../classes app1.jar
Unable to access jarfile app1.jar
Campbell Ritchie wrote:Why are you putting your own work into the Java™ installation folders? Create your own folder, a bit like this
Open command line
Write "mkdir java" (or similar)
Write "cd java"
. . . and you can gain access to your Java™ work simply by using the "cd" instruction next time.
Hi Campbell;
actually i have tried to create a new folder under C:/ directory, but i am not able to compile .java when i use this command:
C:\>javac MyApp.java
'javac' is not recognized as an internal or external command, operable or batch file.
so my temporary solution is to go to javac directory and then use javac ...
In that case you have to add the path to java bin (e.g. C:\Program Files\Java\jdk_xxx\bin) to your PATH environment variable. Remember to restart cmd after that.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Look at the Java™ Tutorials section about getting started and the "common problems" link. The first error it describes is exactly what you are suffering. You need to set a system PATH, and the Windows® installation link (§4) tells you how to do that. Forget about "optional"; just set a PATH
Don't set a system CLASSPATH at this stage.