My java app needs to put a directory of jar files on the classpath. It's
a pain to specify every jar file explicitly on the command line, because
the files are going to change from time to time.
I've seen a variety of ways to automatically include all the jar files
in a directory using batch files and shell scripts. The trouble is that
these scripts look like real hacks, and people are really doing
backflips to do what should be very simple.
Do more recent versions of java have a command line option to do what
I'm looking for? Something like "java -mylibdir=/mylib"? I don't see it,
but sometimes these things are easy to miss.
Thomas Schodt - 25 Feb 2007 09:36 GMT
> ... put a directory of jar files on the classpath.
> ...
> Do more recent versions of java have a command line option to do what
> I'm looking for? Something like "java -mylibdir=/mylib"?
It's been available for a long time.
http://www.google.com/search?q=java+ext+dirs
Chris Uppal - 25 Feb 2007 14:46 GMT
> http://www.google.com/search?q=java+ext+dirs
I doesn't really mean the same thing as loading stuff from the normal
classpath, though. Code loaded as a "standard extension" is loaded by a
different classloader in a different security context.
I'd avoid using the extension mechanism completely.
-- chris
Arne Vajhøj - 25 Feb 2007 16:11 GMT
>> Do more recent versions of java have a command line option to do what
>> I'm looking for? Something like "java -mylibdir=/mylib"?
>
> It's been available for a long time.
>
> http://www.google.com/search?q=java+ext+dirs
That is a global thing and just like CLASSPATH env var should
be general avoided and only used where it is really needed.
Arne
Thomas Kellerer - 25 Feb 2007 09:46 GMT
Chris wrote on 25.02.2007 10:17:
> My java app needs to put a directory of jar files on the classpath. It's
> a pain to specify every jar file explicitly on the command line, because
[quoted text clipped - 8 lines]
> I'm looking for? Something like "java -mylibdir=/mylib"? I don't see it,
> but sometimes these things are easy to miss.
The preferred way is to create a manifest file in your "main" jar, that
references all other jars in the directory. This step can be automated during
build (NetBeans for one, will automatically do that for you, but it's quite easy
to do with Ant as well).
Having said that, the documentation for Java6 at
http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html
http://java.sun.com/javase/6/docs/technotes/tools/solaris/java.html
contains a description that might be what you are looking for:
"As a special convenience, a class path element containing a basename of * is
considered equivalent to specifying a list of all the files in the directory
with the extension .jar or .JAR (a java program cannot tell the difference
between the two invocations). "
I haven't used it though.
A third option is to write your own classloader that simply includes all files
from the base directory.
Thomas
Arne Vajhøj - 25 Feb 2007 16:10 GMT
> My java app needs to put a directory of jar files on the classpath. It's
> a pain to specify every jar file explicitly on the command line, because
[quoted text clipped - 8 lines]
> I'm looking for? Something like "java -mylibdir=/mylib"? I don't see it,
> but sometimes these things are easy to miss.
Java 1.6 supports wildcards in classpath to mean all jars in dir.
Arne