Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Using separate classpaths for separate classes?

Reply
Thread Tools

Using separate classpaths for separate classes?

 
 
Frank Fredstone
Guest
Posts: n/a
 
      06-27-2006
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.
 
Reply With Quote
 
 
 
 
Jean-Francois Briere
Guest
Posts: n/a
 
      06-27-2006
Should work.
Make sure that some-a.jar and some-b.jar are NOT is the JVM class path.

Regards

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ant, packages, and classpaths. Abbasi Dhilawala Java 0 06-29-2004 09:33 PM
Ant and classpaths Elisa Java 2 02-23-2004 08:39 AM
Executable Jars - why are they so rigid with classpaths ? deegoogle Java 3 11-18-2003 12:55 AM
overloading, third party encapsulation, and compiler classpaths Wayne Berke Java 0 09-19-2003 02:49 AM
tomcat's classpaths Daniel Java 2 08-23-2003 12:30 PM



Advertisments