2

In my webservice application I have to integrate a third party module to validate business rules, these modules are shipped with rather old libraries.

The old libraries are in conflict with my newer one.

Is there a way to isolate the third party module in a seperated thread/classloader within the running webservice?

Alex
  • 4,033
  • 9
  • 37
  • 52

2 Answers2

1

What you are looking for is called OSGi.

Luigi R. Viggiano
  • 8,659
  • 7
  • 53
  • 66
  • For my needs OSGi feels like to break a butterfly on a wheel, isn't there a more easier way? – Alex Feb 15 '13 at 14:02
  • Java 8 will contain modularization, named [project jigsaw](http://openjdk.java.net/projects/jigsaw/), I would have a look there too. – Luigi R. Viggiano Feb 15 '13 at 15:11
0

Sure, but you will have to use it via reflection like this:

ClassLoader classLoader = new URLClassLoader (
    new URL [] {/* Classpath or isolated module here */},
    ClassLoader.getSystemClassLoader ().getParent ());

Class <?> isolatedModuleClass = classLoader.loadClass (
    /* Full name of class from isolated module */);

Object isolatedObject = 
    isolatedModuleClass.
        getConstructor (/* Constructor argument types */).
            newInstance (/* Constructor arguments */);

Object result =
    isolatedModuleClass.
        getMethod (/* Method name */, /* Method parameter types */).
            invoke (isolatedObject, /* Method arguments */);
Mikhail Vladimirov
  • 13,572
  • 1
  • 38
  • 40