4

I'm struggling to get my jar file working from a web browser. When I run the applet from Eclipse everything is OK, but from the browser I get a NoClassDefFoundError :

Exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/bouncycastle/openpgp/PGPException
java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/bouncycastle/openpgp/PGPException
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3116)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1498)
at java.lang.Thread.run(Thread.java:662)

The PGPException is in the org/bouncycastle/openpgp/ directory of the bcpg-jdk16-146.jar archive though... My JAR contains both libraries from bouncycastle and a my applet class. Here its architecture :

META-INF
    -MANIFEST.MF
    -CNSAPPLE.SF
    -CNSAPPLE.RSA
lib
    -bcprov-jdk16-146.jar
    -bcpg-jdk16-146.jar
com
    -CNSApplet.class

The manifest file defines the class path and the main class as it follows:

Class-Path: lib/bcpg-jdk16-146.jar lib/bcprov-jdk16-146.jar

Main-Class: com.CNSApplet

And the html code calling the applet:

<applet code="com.CNSApplet.class" width="800" height="300" archive="cnsapplet.jar">

Of course the html file is in the same directory of the cnsapplet jar file.

I've tried to make my jar with the sun method and this other one.

Community
  • 1
  • 1
renard
  • 1,368
  • 6
  • 20
  • 40

2 Answers2

2

The Java default ClassLoader doesn't look for JAR files embedded in your JAR. That means that in order to include the libraries in your JAR's classpath you can do either of the following:

  1. Unpack the library JARs and then pack the class files into your own JAR
  2. Leave the library JARs out of your JAR, and then reference them using the manifest file (just like you did).
Kraylog
  • 7,383
  • 1
  • 24
  • 35
  • I tried both of these solution but I get always the same exception. I've also tried to remove the code related to the BC libraries and the import accordingly. But apparently when the browser retrieves the jar, it is like if it was the previous jar with the BC libraries! – renard Nov 29 '11 at 12:28
  • 1
    Sounds like a caching problem - make sure you clear the browser cache before testing, as most browsers will cache JARs to not have to download them again. – Kraylog Nov 29 '11 at 14:48
  • That was propably the issue, it works now! Thanks, I'll have this in mind for the next times – renard Nov 29 '11 at 16:45
0

The Class-Path manifest entry in a JAR file points to the file system (relative to the JAR file) and not to files embedded within the JAR file.

Either unpack the BC jars and add their content to your JAR file or offer the BC jars as separate downloads. You can specify more then one JAR file in the applet tag's archive attribute, by separating them with a comma.

Since the BC jars are signed and the signature is lost if you repack the content into your own JAR file, the best solution would probably be to offer them as separate files and list them in the archive attribute.

jarnbjo
  • 33,923
  • 7
  • 70
  • 94