Classpath = ?

Ok, I didn't want to post this question but it turns out that I have to....

If I choose to set the classpath environment variable in Windows then what should it be assuming the following is the path to my JDK:

C:\Program Files\Java\jdk1.6.0_02

If somebody could answer this for me without referring me to a link about setting the classpath then that would be great.

thanks.

[406 byte] By [thousea] at [2007-11-27 10:06:50]
# 1

> If I choose to set the classpath environment variable

> in Windows

Don't. Instead specify classpath on the command line.

> then what should it be assuming the

> following is the path to my JDK:

It doesn't matter where the JDK is. Classes that are part of the JDK or JRE are automatically found relative to that installation. Classpath is only needed for your own and third party classes.

> If somebody could answer this for me without

> referring me to a link about setting the classpath

> then that would be great.

What, you want us to regurgitate what's there like you're a baby bird? If you're not willing to read and research without being spoonfed, you're already doomed.

http://wiki.java.net/bin/view/Javapedia/ClassPath

http://java.sun.com/j2se/1.5.0/docs/tooldocs/findingclasses.html

http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html

http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/classpath.html

http://www-106.ibm.com/developerworks/edu/j-dw-javaclass-i.html

java -cp .;<any other directories or jars> YourClassName

You get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

javac -classpath .;<any additional jar files or directories> YourClassName.java

You get a "cannot resolve symbol" message because the compiler can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

jverda at 2007-7-13 0:43:16 > top of Java-index,Java Essentials,New To Java...
# 2

>

> java -cp .;<any other directories or jars>

> YourClassName

> You get a NoClassDefFoundError message because the

> JVM (Java Virtual Machine) can't find your class. The

> way to remedy this is to ensure that your class is

> included in the classpath. The example assumes that

> you are in the same directory as the class you're

> trying to run.

chirp!!! chirp, chirp!

Jverd - what happened? I thought we were friends?

I've read a lot about setting the classpath - and I'm willing to research... I just never understood that the core classes didn't need to be found by way of the cp. Anyways - I'm trying to compile a class that I wrote from within the directory which it resides and I'm getting the error above .... if the classes that are part of the JDK are being found then it must be my class that isn't found - I'm not using any 3rd pary classes.... everything I've read tells me that the current directory is also searched for referenced classes - so what's up?

thousea at 2007-7-13 0:43:16 > top of Java-index,Java Essentials,New To Java...
# 3

> everything I've read tells me that the current directory is also searched for

> referenced classes

Read more, read different, read better.

The "finding classes" link gives four different rules that can be used for finding user classes and makes it clear that each of them overrides the previous ones.

pbrockway2a at 2007-7-13 0:43:16 > top of Java-index,Java Essentials,New To Java...
# 4

> Jverd - what happened? I thought we were friends?

I don't know. Were we? Did I say something uncalled for?

> I've read a lot about setting the classpath - and I'm

> willing to research...

Okay, that's fine. But I don't know what you've read or in what way it didn't help you, so when you say, "Don't give me links," that basically leaves me (or whoever) to read your mind as to what information you need an in what form to spoonfeed it to you.

> I just never understood that

> the core classes didn't need to be found by way of

> the cp.

Yeah, a lot of people don't. I didn't at one point. So I told you.

> Anyways - I'm trying to compile a class that

> I wrote from within the directory which it resides

That by itself means nothing. You'll have to provide details. Exact paths, exact command, etc.

Of course, if you go through the links I provided, you'll probably find examples that you can use, and when those work, compare them to what you're doing and see what's different.

> the current directory is also searched for referenced

> classes

Um, that's rather vague.

If you don't specify an explicit classpath, then "." (dot, the current directory) is the classpath (at least as of 1.3 or 1.4). If you do specify an explicity classpath, then "." isn't implicitly there, and you have to put it there if you want it.

Also, if you have class Foo in package a.b--that is, a.b.Foo--then the classpath must contain the parent directory of a. CD-*** to a/b and putting "." on the classpath doesn't work.

For more details, read the links.

jverda at 2007-7-13 0:43:16 > top of Java-index,Java Essentials,New To Java...