Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classpath

 
Venkateshwar Rao Eturi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
I am very new to Java.

I installed java on my Windows XP machine, got problems with compilation. After setting classpath in system variables, my program could compile. But when try to run the prog from command line, I get " No class def found error ". It is definitely with the classpath settings, but can anybody help me to set it correctly please?



Thanks,
Venkat
 
Sumit Bisht
Ranch Hand
Posts: 331
Python Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a common problem with java/allied java technologies.
You can solve this by right-clicking My Computer icon,Select Properties,select the advanced tab & click Environment Variables.

Here create a variable named PATH with value as
.;<JDK installation dir>\bin;<JRE installation dir>\rt.jar;<JDK installation dir>\lib\tools.jar;
It should work fine.
Note: bin is needed for tools like java and javac,rt jarfile contains runtime classes needed by java(java.lang package)

At command prompt, now try set path
You should see the files/dirs mentioned previously.
For more info, please download the java tutorial from java.sun.com
 
Sumit Bisht
Ranch Hand
Posts: 331
Python Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For classpath related problems try setting CLASSPATH variable with .; at the start of the list of classpaths.
. means the jre will search the current folder first for the class file
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not supposed to set the classpath variable, only the path. Old books told you how to update the classpath, but that is no longer necessary.

Least of all should you add C:\Java\jdk1.6.0_06\bin to your classpath. That belongs in the PATH only. There ought to be a ;.; somewhere in the classpath, but it is virtually always included by default. The . means "current folder."

What you do on Windows is to create a folder, let's call it C:\JavaPrograms, but you can have it anywhere and call is something different.
Then you navigate to it by calling

cd C:\JavaPrograms

and your prompt says c:\JavaPrograms>: or similar.

Then you compile your java source, maybe Foo.java with the "java Foo.java" command, and you can tell when it works because the prompt appears with no error messages.
Then you execute the class file with "java Foo" - no .java or .class, but you may need command-line arguments.

Reasons for the error you are getting:
  • You are in a different folder with the command prompt.
  • You have put a package declaration in your source and not gone to the base folder to run the class.
  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic