CLASSPATH pointing to a directory instead of a jar

Hi All,

Lets say I have a directory with 7 jar files and I need all of them in the CLASSPATH. If I set my CLASSPATH to the directory, I get a runtime exception that it doesn't know about the classes references in the jar. If I set my CLASSPATH to <directory>\<filename>.jar , it works. So does this mean that for CLASSPATH, we need to explicitly specify the name of the jar?

Thanks.

[415 byte] By [leostar_10a] at [2007-11-26 18:19:48]
# 1
Yes you do.I think I it is changed in Java6 (but that might just be the -cp, not setting CLASSPATH) so you can use wild cards (so set the classpath to /blah/libs/*.jar).
mlka at 2007-7-9 5:53:35 > top of Java-index,Java Essentials,New To Java...
# 2

yikes, so now CLASSPATH will contain 7 jar file names, even if all of them reside in the same directory.

I am using 1.5 on windozzz.

Another annoyance is when I set the CLASSPATH in Control Panel -> System and I run set from DOS prompt, it shows the old CLASSPATH. I have to basically open a new DOS prompt to get the new CLASSPATH changes. Something I am missing to make life easier?

leostar_10a at 2007-7-9 5:53:35 > top of Java-index,Java Essentials,New To Java...
# 3

> yikes, so now CLASSPATH will contain 7 jar file

> names, even if all of them reside in the same

> directory.

That's always been so.

> I am using 1.5 on windozzz.

Irrelevant.

> Another annoyance is when I set the CLASSPATH in

> Control Panel -> System

You shouldn't be doing this, IMO. It's usually a waste of time, because every project has a different CLASSPATH. The CLASSPATH environment variable is ignored by Java EE containers and IDEs, so it's almost useless.

> and I run set from DOS

> prompt, it shows the old CLASSPATH. I have to

> basically open a new DOS prompt to get the new

> CLASSPATH changes. Something I am missing to make

> life easier?

Just "set CLASSPATH=..." in the DOS window if you need it and don't set the environment variable.

%

duffymoa at 2007-7-9 5:53:35 > top of Java-index,Java Essentials,New To Java...
# 4
Yes, don't set the CLASSPATH variable. Use a build tool, and the manifest.
mlka at 2007-7-9 5:53:35 > top of Java-index,Java Essentials,New To Java...
# 5

ok, coming back to CLASSPATH, if the directory contains a bunch of class files instead of jar file and I point my CLASSPATH to the directory, that works. So to summarize:

If the class files are packaged in a jar file -> CLASSPATH should explicitly point to the jar file

If the class files are not packaged in a jar -> CLASSPATH can point to the directory where the .class files are located.

leostar_10a at 2007-7-9 5:53:35 > top of Java-index,Java Essentials,New To Java...
# 6

> ok, coming back to CLASSPATH, if the directory

> contains a bunch of class files instead of jar file

> and I point my CLASSPATH to the directory, that

> works.

So to summarize:

> If the class files are packaged in a jar file ->

> CLASSPATH should explicitly point to the jar file

Yes.

> If the class files are not packaged in a jar ->

> CLASSPATH can point to the directory where the .class

> files are located.

Not always to the location where the .class files are located, to the location of the root of the package hierarchy.

So if your classes start with a "package foo.bar.baz;" statement, you want to point to the directory where "foo" lives.

%

duffymoa at 2007-7-9 5:53:35 > top of Java-index,Java Essentials,New To Java...