> > How can I create a custom class loader which loads classes only from a
> > specific jar?
[quoted text clipped - 3 lines]
> > entry point, how can I set the class loader for every class in the
> > jars?
Thank You.
> WEB-INF/lib ? No !
Let me be more specific. The problem I have is that both a.jar and
b.jar have some classes which are the same ( duplicated ). If I put
them toghether in WEB-INF/lib the classloader gets messed up due to the
duplicate classes.
> Because they will be loaded by a parent classloader.
>
[quoted text clipped - 3 lines]
> URLClassLoader cl = new URLClassLoader(urlofjar);
> X o = (X)Class.forName(clsnam, true, cl).newInstance();
This seem to be a good possibility however as there is no entry point
and there are a lot of classes, I'm not sure how I can control the
creation of each class and use my own class loader.
Also how can I have the web server load the jars at some point if they
are not in web-inf/lib?
> Arne
Arne Vajhøj - 30 Sep 2006 20:28 GMT
>> WEB-INF/lib ? No !
> Let me be more specific. The problem I have is that both a.jar and
> b.jar have some classes which are the same ( duplicated ). If I put
> them toghether in WEB-INF/lib the classloader gets messed up due to the
> duplicate classes.
Yes.
You need two custom classloaders one for each jar and the jars
must not ne in path for parent classloaders.
>> URLClassLoader cl = new URLClassLoader(urlofjar);
>> X o = (X)Class.forName(clsnam, true, cl).newInstance();
[quoted text clipped - 4 lines]
> Also how can I have the web server load the jars at some point if they
> are not in web-inf/lib?
The Class.forName code above explicit specify classloader.
The URL for the classloader can be any URL including file
URL's.
Note that the deployment of you app will become a bit tricky, but
that is how it has to be.
Arne