...

View Full Version : Java classpath



Pompiuses
12-15-2004, 02:03 PM
Java newbie here......

I'm on a winxp pc and got java installed in C:\j2sdk1.4.2_06

I've set the PATH environment variable to point to C:\j2sdk1.4.2_06\bin

I'm getting an errormessage all the time when trying to run my classes:
Exception in thread "main" java.lang.NoClassDefFoundError: MyClass

I suspect this is coming from not setting the CLASSPATH.

Where should the CLASSPATH point to??

shmoove
12-15-2004, 03:38 PM
If you are running from the command prompt then you can use the -cp or -classpath parameters in the command line to specify the classpath. Use "java -?" to find out all the options you have.

shmoove

Pompiuses
12-15-2004, 03:41 PM
If you are running from the command prompt then you can use the -cp or -classpath parameters in the command line to specify the classpath. Use "java -?" to find out all the options you have.

shmoove

If I have no classpath at all everything works fine. But since I've installed Tomcat I need to have a classpath variable.

I can run my programs from anywhere on the disk using: java -cp "." MyClass
...and it works fine. But it's very bothersome.

How can i avoid using -cp ??

I was into java about 4 years ago, and never had a problem with this. What've changed?

KeZZeR
12-15-2004, 04:06 PM
I've had problems setting up with my IDE using the Java SDK so instead i used the JDK and i had no problems. The difference is that they renamed it with the newer version. Old versions = Java SDK, new versions = JDK. It's on the site, i think it's 1.5.0. Anyway, try JDK out instead and see if it fixes the problem.

Roelf
12-15-2004, 08:01 PM
I can run my programs from anywhere on the disk using: java -cp "." MyClass
...and it works fine. But it's very bothersome.
that is because with the -cp option, you set the current directoryas the classpath.

How can i avoid using -cp ??
By setting the classpath in your environment variables. add (or change) the CLASSPATH environment variable, with all the folders in it from where you want to use your classfiles. You can also add folders to the classpath in a cmdfile with the next command:
set %CLASSPATH%=%CLASSPATH%;yourpathname

Then it will be added for the current commandwindow



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum