Karsten Wutzke schrieb:
> Hi all!
>
> Does anyone know what I am doing wrong? How do I make it work?
>
> TIA
> Karsten
Have you heard of fatjar till now?
http://fjep.sourceforge.net/
it seems to be pretty close on what you are doing..
christian
> I want to bundle my app in one JAR file. In the lib sub dir of the
> JAR, there should be all JAR's that the application depends on, here
> bcel-5.2.jar (plus several others).
You are probably better off unjarring the jars and jarring the lot together.
> Since adding the JAR's to the manifest's Class-Path entry didn't work,
> I tried my luck with a URLClassLoader. The code itself is too easy. I
[quoted text clipped - 10 lines]
> I expected the class loader to become a child of the bootstrap class
> loader.
If you use the constructor that doesn't specify the parent, then you get
the system class loader as parent. This is what the API docs mean by
"the default delegation parent ClassLoader". Why they use such an obtuse
phrase, I don't know. If you want the bootstrap class loader to be the
direct parent, add ", null".
> The problem is: I don't really know where to put the above code.
> Currently it is in my "config" class. However, the class loader
> doesn't seem to be put into the delegation hierarchy, otherwise the
> classloader would find the classes from the bcel JAR. I checked the
> URL and JAR location inside my JAR, they seem to be correct.
The delegation happens the other way around. A class loader delegates to
its parent. So your class loader delegates to the system (and hence
boot) class loader, not the other way around. You need to specify your
class loader to load a class from it, for instance using
Class.forName(String,boolean,ClassLoader).
If you want to link your own code to that, then you either need another
class loader that delegates to your "cllLibs" class loader, or make one
class loader to load it all (other than your initial code to create the
class loader and kick off the app).
Tom Hawtin