4

我正在努力让我的 jar 文件从网络浏览器中运行。当我从 Eclipse 运行小程序时,一切正常,但是从浏览器中我得到一个 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)

PGPException 位于 bcpg-jdk16-146.jar 存档的 org/bouncycastle/openpgp/ 目录中……我的 JAR 包含来自 bouncycastle 的库和我的小程序类。这里是它的架构:

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

清单文件定义了类路径和主类,如下所示:

类路径:lib/bcpg-jdk16-146.jar lib/bcprov-jdk16-146.jar

主类:com.CNSApplet

以及调用小程序的 html 代码:

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

当然html文件是在cnsapplet jar文件的同一目录下。

我试着用sun 方法另一个方法来制作我的罐子。

4

2 回答 2

2

Java 默认的 ClassLoader 不会查找 JAR 中嵌入的 JAR 文件。这意味着为了将库包含在 JAR 的类路径中,您可以执行以下任一操作:

  1. 解压缩库 JAR,然后将类文件打包到您自己的 JAR 中
  2. 将库 JAR 保留在 JAR 之外,然后使用清单文件引用它们(就像您所做的那样)。
于 2011-11-29T11:25:49.860 回答
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.

于 2011-11-29T11:27:53.317 回答