This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi there I'm pretty new to Java and having some trouble so I hope someone here can help me.. (I've searched some threads on this topic but still having trouble!)
I downloaded JDK5.0 Update 9 with NetBeansIDE and downloaded it into the directory C:\Program Files\Java\jdk1.5.0_09...
I am using the command line as recommended in the book Headfirst Java as NetBeans is much too complex for me at this stage.
I am storing my programs in the following directory structure C:\java\myclasses\HelloWorldApp\HelloWorldApp.java compiling to C:\java\myclasses\HelloWorldApp\HelloWorldApp.class
C:\java\myclasses\SimpleDotComGame\SimpleDotComGame.java compiling to C:\java\myclasses\SimpleDotComGame\SimpleDotComGame.java etc.
I have set up my PATH correctly as C:\Program Files\Java\jdk1.5.0_09\bin and it is working fine.
However I am having serious problems with CLASSPATH. I have tried a few of the suggestions here but none seem to work consistently. I have used set CLASSPATH=.; and then gone into one of my program directories and the program has compiled ok but it only works in that directory for that program and won't work for any others. I get NoClassDefFoundError.
It is very frustrating. I have also set this variable from the System menu in Control panel with no luck.
Is there any way that you can set your classpath to always look for the classes in your current directory?
However I am having serious problems with CLASSPATH. I have tried a few of the suggestions here but none seem to work consistently. I have used set CLASSPATH=.;
I suggest you completely avoid creating or setting a CLASSPATH environment variable. You need to learn how to compile programs using the -classpath option in both the javac and java commands. The -classpath option overrides the CLASSPATH environment variable anyway, and the paths you list in the -classpath option will be different for different files.
For a simple program that has no package statement as the first line in the file and does not have any lines that start with "import", you can compile your programs like this: