Search code examples
resourcesclasspathjnlpexecutable-jarjava-web-start

does JWS support to launch One-Jar


Can I supposed to launch One-Jar using JWS? One-JAR provides custom classloader that knows how to load classes and resources from a jars inside an archive whereas in JWS we need to specify each JAR that is being used in resources.

What I supposed to specify in JNLP if I am trying to launch One-Jar -

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="">
    <information>
        <title>Application</title>
        <vendor>ABC</vendor>
    </information>
    <resources>
        <!-- Application Resources -->
        <j2se version="1.5+"
              href="http://java.sun.com/products/autodl/j2se"/>
        <jar href="Application.jar" main="true" download="eager" />
    </resources>
    <application-desc main-class="com.simontuffs.onejar.Boot">
  </application-desc>
   <update check="background"/>
    <security>
        <all-permissions/>
      </security>
</jnlp>

My Application JAR that is One-JAR contains -

com\simontuffs\onejar\<contains complied classes> like JarClassLoader$1.class etc
lib/<contains all jar>
OneJar.class
main/<my application's jar>
META-INF\MANIFEST.MF\ <contains >

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1
Created-By: One-Jar 0.96 Ant taskdef
Main-Class: com.simontuffs.onejar.Boot
One-Jar-Main-Class: com.application.main.Entry

Name: com/simontuffs/onejar/Boot$3.class
SHA1-Digest: +LPrezs+UEFcE3J7QvumcAEO8Z0=

Name: OneJar.class
SHA1-Digest: 28pzzJWqEpLk1xFwJ/jsAav8LyI=

Name: lib/commons-io-1.4.jar
SHA1-Digest: qHYtB+ds/eI5Ulel2ke6fB29Pc4=

etc..etc..

How to specify these com/simontuffs/onejar/Boot$3.class paths in resource ?


Solution

  • Part of the problem of supporting tools like One-Jar is that loading Jars within Jars requires a custom class-loader. By default JWS will use the usual JRE class-loaders - which do not support it.

    There are two possible ways that you might get around that (that I know of).

    1. Get access to the custom class-loader.

    Get an instance of the custom loader used by One-Jar and set it as the context class-loader. This would require a trusted app., but I get the impression that your app. is trusted.

    I have no idea if the One-Jar API provides this loader for your own app.'s use.

    2. Use some options when building.

    From Options and VM Properties..

    one-jar.jar.names

    • true: Recorded classes are kept in directories corresponding to their jar names.
    • false: Recorded classes are flattened into a single directory. Duplicates are ignored (first wins)

    The 2nd option sounds like a standard 'fat jar'. That should work with the conventional (default) class-loader used by JWS.