Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

Specify lib dir on command line

Thread view: 
Chris - 25 Feb 2007 09:17 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
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.