Search code examples
javaappletjava-web-start

Does JWS load JARs inside JAR for applets?


I'm maintaining a Java applet launched via Java Web Start but I know little about this technology (we are in the process of moving away from applets but we need some maintenance on it). This applet depends on some external JAR files (batik, etc.).

We use gradle as the build system. We build a normal JAR and a fat JAR (with the com.github.johnrengelman.shadow plugin) as follows:

sourceSets {
  main {
    java {
    }
  }
}
repositories {
  flatDir {
    dirs 'lib'
  }
}
dependencies {
  compile 'commons-lang:commons-lang:2.0',
    'jargs:jargs:1.0',
    'org.apache.xmlgraphics:batik-svggen:1.7',
    'org.apache.xmlgraphics:batik-dom:1.7',
    'org.apache.xmlgraphics:batik-awt-util:1.7',
    'org.apache.xmlgraphics:batik-util:1.7',
    'org.apache.xmlgraphics:batik-xml:1.7',
    'xerces:xercesImpl:2.8.0'
}
jar {
  manifest {
    attributes  'Application-Name': project.name,
                'Permissions': 'all-permissions',
                'Implementation-Title': project.name,
                'Implementation-Version': version,
                'Main-Class': 'Foo',
                'Class-Path': configurations.compile.files.collect{ "lib/${it.name}" }.join(' ')
  }
  baseName project.name
  // include dependencies into lib dir in produced jar
  into('lib') {
    from configurations.runtime
  }
  from "README.md"
}
shadowJar {
  baseName project.name
}

gradle includes the JAR files in lib/ folder inside the main JAR and they are added to the Class-Path in MANIFEST.MF.

The applet works on client computers with the normal JAR but I don't fully understand why.

Somehow, the JAR files are loaded when Java Web Start launches the applet. They are not mentioned in the JNLP file (no <resource>) and there is no class loader (we don't use JarRsrcLoader or similar) so I guess it's because they are in Class-Path but I am not sure and I haven't been able to produce a MWE. In fact all the information that I have found states the opposite (at least for applications as opposed to applets).

Does anybody know if it's the case or a simple explanation/tutorial ?


Solution

  • Well, I was wrong. In fact the JAR files are not loaded: when one tries to access the functionality that needs batik, it fails. This confirms my readings and @eckes and @zakki comments.

    I also discovered that I can simplify our build.gradle file.