Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use a <a href="http://docs.oracle.com/javase/7/docs/api/java/net/URLClassLoader.html" rel="nofollow"><code>URLClassLoader</code></a> to load the second Jar at runtime.</p> <p>Depending on your needs, you may need a bridging interface (one that exists in both Jars) that you would call from your 'exe' to get the second Jar running...or you could simply use the second Jar's <code>main</code> method ;)</p> <p>The other choice you have is to run another JVM.</p> <p><strong>UPDATE</strong></p> <p>In order to physical seperate the two elements of your application. You have a Jar wrapped in a EXE (aka launcher) and another Jar which is your application (aka application) (I assume).</p> <p>So. Your launcher should have absolutely no idea about your application (little to no compile time dependencies).</p> <p>Some how, we need to dynamically load the application from the launcher. To do that, we need a few things.</p> <p>We need to be able to load the application into the launchers class loader context (so we can see it) and we some we to be able to load the application.</p> <p><strong>Dynamic ClassLoading</strong></p> <p>This can be achieved simply through the use of <code>URLClassLoader</code></p> <pre><code>URLClassLoader loader = new URLClassLoader(new URL[]{new File("path/to/your/jar/Application.jar").toURI().toURL()}); </code></pre> <p><strong>Application Loading</strong></p> <p>This can be achieved in one of two ways. You could simply use the <code>URLClassLoader</code> to find a launch the applications <code>main</code> class...</p> <pre><code>// This is essentially the same as saying // the.package.name.to.you.main.class.Main.main(new String[]{}); Class&lt;?&gt; mainClass = loader.loadClass("the.package.name.to.you.main.class.Main"); Method mainMethod = mainClass.getMethod("main", String[].class); mainMethod.invoke(null, new String[]{}); </code></pre> <p>Now, if your application Jar doesn't have a <code>main</code> method, you can use the above example to launch just about any class you want...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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