Specify lib dir on command line

C

Chris

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.
 
T

Thomas Kellerer

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
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.

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
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Chris said:
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.

Java 1.6 supports wildcards in classpath to mean all jars in dir.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top