• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Classpath, lib directory, and lots of libraries!

 
David Irwin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on a current project that requires a long list of third party library jar files. Currently I have placed them all in a lib directory. I currently have a bat file that looks a little something like:



and so on. I find this pretty ugly and I don't like having to edit this file as I add or remove required library files from the project. Is there a way to specify that all jar files found in my lib folder are to be added to the classpath? I've tried the following:



but that doesn't work as it doesn't load any of the jar files in the lib folder. Am I missing something obvious? Is there a much better way to handle loading a large number of library jar files? Thanks.
 
Norm Radder
Rancher
Posts: 5015
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the java Extension feature. It will use the jar files that are in the jre\lib\ext folder. I don't know about compiles though.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no brief solution in java afaik.

You may specify a directory, containing classes, or a jar-file, containing classes.
But not directories, containing jars, containing classes.

There are several ways to work around:
a) The big, fat mama-jar:
Unjar all the jars, and create a super jar, containing all those classes.

Not very elegant, I admit.

b) Move all jars to %JAVA_HOME%/jre/lib/ext where the jvm will look automatically for jars.

Unfortunately some people report it doesn't work for them, while it works for me.
Curious?

Not very elegant too.

c) Generate the classpath on the fly:

Well - you have to translate this to Windows-Scripting Language or to get the native gnu-utils for win32, but you got the idea?
ls *.jar is a brother of dir *.jar, and the 'tr'-command means: translate linefeed to Unix-Pathseparator : (Win: .

It's not very elegant too, in my opinion.
Feel free to find a better one.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may have good reasons for using a .bat file, but have you considered using Ant? It greatly simplifies handling classpathes, up to the point where you can specify that all jars in a directory should be used, no matter how many there are.
 
David Irwin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the responses. I'm glad to see that it isn't something obvious that I've missed, but I'm disappointed that there isn't an elagent solution to this problem. I certainly can't be the only one with this problem. There are some good suggestions above...what have others done?

And Ulf, I do use Ant and do have a "launch" target to run my application and I should have made mention of it. To date that's the best solution I've found.

Thanks again for the replies!
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ANT provides the solution you seek. You create a fileset in your classpath that includes all jar files. Java Jar files also have a solution: use a jar manifiest with a Class-Path setting that lists dependent jars.

Personally, blindly loading all jars in a folder is the antithesis of elegant. How often do you run a Java program that is not started from a script? Never? Probably very infrequently. I would not even put that on the list of possible java enhancements. It would cause more problems than it solves. In fact I would not even characterize it as solving a real problem.
 
I'm just a poor boy, I need no sympathy, because I'm easy come, easy go, little high, little low, little ad
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic