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 / June 2006

Tip: Looking for answers? Try searching our database.

Using separate classpaths for separate classes?

Thread view: 
Frank Fredstone - 27 Jun 2006 07:36 GMT
I need to use classes that require conflicting classpaths, and I have
no access to source code.

Can I instantiate a class with one classpath in effect so that all the
classes it uses are resolved from their classpath, and then
instantiate a different class with a different classpath, so that all
the clasess it uses are resolved from that separate classpath?

Will it work to use URLClassLoader for this? It's not working for me,
but I think I might be making a mistake.

Should it work like this:

URLClassLoader clA = new URLClassLoader(new URL[] {
   new URL("file:///somewhere/some-a.jar"),
});
Class ca = clA.loadClass("some.ClassA");
Object oa = ca.newInstance();

URLClassLoader clB = new URLClassLoader(new URL[] {
   new URL("file:///somewhere/some-b.jar"),
});
Class cb = clB.loadClass("some.ClassB");
Object ob = cb.newInstance();

Then when some.ClassA instantiates some.OtherClass1 and
some.OtherClass2 (invisible to me), they will be loaded from
some-a.jar.

And, when some.ClassB instantiates some.OtherClass1 and
some.Otherclass2 (invisible to me), they will be loaded from
some-b.jar.

So, some.ClassA will never load anything from some-b.jar and
some.ClassB will never load anything from some-a.jar.
Jean-Francois Briere - 27 Jun 2006 07:46 GMT
Should work.
Make sure that some-a.jar and some-b.jar are NOT is the JVM class path.

Regards


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.