Using separate classpaths for separate classes?

Discussion in 'Java' started by Frank Fredstone, Jun 27, 2006.

  1. 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.
     
    Frank Fredstone, Jun 27, 2006
    #1
    1. Advertising

  2. Should work.
    Make sure that some-a.jar and some-b.jar are NOT is the JVM class path.

    Regards
     
    Jean-Francois Briere, Jun 27, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel

    tomcat's classpaths

    Daniel, Aug 21, 2003, in forum: Java
    Replies:
    2
    Views:
    426
  2. Wayne Berke
    Replies:
    0
    Views:
    402
    Wayne Berke
    Sep 19, 2003
  3. deegoogle
    Replies:
    3
    Views:
    364
    Dave Glasser
    Nov 18, 2003
  4. EvgueniB
    Replies:
    1
    Views:
    674
    Anthony Borla
    Dec 15, 2003
  5. Elisa

    Ant and classpaths

    Elisa, Feb 22, 2004, in forum: Java
    Replies:
    2
    Views:
    441
    Elisa
    Feb 23, 2004
Loading...

Share This Page