Let's suppose I have some classes stored in a jar file.
If I want my application to be able to access those classes at runtime, I can achieve this by adding the jar file to the classpath.
Or, I can set my classpath to be '/myclasses/' and know that if I had extracted my .jar file into the myclasses directory, they would also be found at runtime.
The second option is nice because if I expand more jars under the myclasses structure then the '/myclasses/' classpath would not need to change in order to find them.
My question, finally :-), is...is it possible to somehow specify classpath as '/myjars/' and just plonk all the jars I need in that folder? So that I can add further jars in the future without having to A) change the classpath, or B) have t worry about expanding them out?
I can't seem to get it to work and have tried various combination of *, *.jar et cetera.
SCJP 1.4 (93%)<br />SCJD (In progress. It can run, but it can't hide...)
I'm afraid the second option is not possible. For *.zip or *.jar, the classpath must end with the name of *.zip/jar file. However, for *.class files, the classpath ends with directory name that contains the *.class files.
I suppose that I could write a method that would look in a given folder and add all the .jar files it finds there to a classpath setting...but then of course the JVM has already started and it is generally accepted that you should not change the classpath of the JVM once it is running.
I wonder if there is a mechanism in 1.4 or 1.5 that allows a classpath to be updated at runtime...
eeek! Some horrible proposed solutions!! What you want is a custom class loader. Please oh please don't implement any of the hacks that have been suggested, or at least, don't let them go into production where I might see them one day (please!)
All it sounded like Simon wanted to do was avoid having to edit the classpath whenever a new jar was added to a project. I suggested ways to build a classpath rather than extract all the jars into one myclasses directory.
Custom classloader seems like overkill. Or I missed the boat, but don't consider my suggestions hacks. [ March 01, 2005: Message edited by: Carol Enderlin ]
Joined: Dec 09, 2000
Thanks for adding to the pool of suggestions.
Do you have a code example of how a "custom class loader" could be used to load a required class; given a known location that contains a number of jar files, one of which, indeed, contains the class.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com