Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've not tried this myself, but from memory each clashing class needs to be in a sibling classloader and any communication between the two needs to go through a common ancestor. However, the ancestor cannot (AFAIK) "directly" reference classes from its children and must access them through the reflection API.</p> <p>Something along these lines ought to work (dry-coded) YMMV. Comments and error-spotting welcome.</p> <pre><code>class Orchestrator { URL[] otherAppClasspath = new URL[] { new URL("file:///vendor-api.jar"), new URL("file:///hibernate2.jar"), new URL("file:///code-extending-vendor-api.jar" }; URLClassLoader otherAppLoader = new URLClassLoader(otherAppClasspath); URL[] yourAppClasspath = new URL[] { new URL("file:///myapp.jar"), new URL("file:///hibernate3.jar") }; URLClassLoader yourAppLoader = new URLClassLoader(yourAppClasspath); public void start() { Method yourAppEntryPoint = yourAppLoader.findClass("com/company/Main").getMethod("start", new Class[] { Orchestrator.class } ); yourAppEntryPoint.invoke(null, new Object[] { this }); } public static void main(String[] args) { new Orchestrator().start(); } // define some abstracted API here that can be called from your app // and calls down into classes in the other app public String getSomeResultFromOtherApp(int someArgument) { Method otherAppAPI = otherAppLoader.findClass("com/company/ExtendingAPIClass").getMethod("getSomeResult", new Class[] { Integer.class }); return (String)otherAppAPI.invoke(null, new Object[] { someArgument }); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload