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.

4

2 に答える 2

2

Java のデフォルト ClassLoader は、JAR に埋め込まれた JAR ファイルを検索しません。つまり、JAR のクラスパスにライブラリを含めるには、次のいずれかを実行できます。

  1. ライブラリ JAR を解凍し、クラス ファイルを独自の JAR にパックします。
  2. ライブラリ JAR を JAR から除外し、マニフェスト ファイルを使用してそれらを参照します (先ほど行ったように)。
于 2011-11-29T11:25:49.860 に答える
0

JAR ファイルの Class-Path マニフェスト エントリは、JAR ファイル内に埋め込まれたファイルではなく、(JAR ファイルに関連する) ファイル システムを指します。

BC jar を解凍してそのコンテンツを JAR ファイルに追加するか、BC jar を個別のダウンロードとして提供します。複数の JAR ファイルを、applet タグの archive 属性にカンマで区切って指定できます。

BC jar は署名されており、コンテンツを独自の JAR ファイルに再パックすると署名が失われるため、最善の解決策はおそらくそれらを個別のファイルとして提供し、アーカイブ属性にリストすることです。

于 2011-11-29T11:27:53.317 に答える