简体   繁体   English

带有bouncycastle库的jar文件:NoClassDefFoundError

[英]jar file with bouncycastle libraries: NoClassDefFoundError

I'm struggling to get my jar file working from a web browser. 我很难从网络浏览器中获取我的jar文件。 When I run the applet from Eclipse everything is OK, but from the browser I get a NoClassDefFoundError : 当我从Eclipse运行applet时一切正常,但是从浏览器中我得到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. PGPException位于bcpg-jdk16-146.jar存档的org / bouncycastle / openpgp /目录中,但是......我的JAR包含来自bouncycastle的库和我的applet类。 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 类路径:lib / bcpg-jdk16-146.jar lib / bcprov-jdk16-146.jar

Main-Class: com.CNSApplet Main-Class:com.CNSApplet

And the html code calling the applet: 和调用applet的html代码:

<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. 当然,html文件位于cnsapplet jar文件的同一目录中。

I've tried to make my jar with the sun method and this other one . 我试图用太阳方法另一个 方法制作我的罐子。

The Java default ClassLoader doesn't look for JAR files embedded in your JAR. Java默认的ClassLoader不会查找JAR中嵌入的JAR文件。 That means that in order to include the libraries in your JAR's classpath you can do either of the following: 这意味着为了将库包含在JAR的类路径中,您可以执行以下任一操作:

  1. Unpack the library JARs and then pack the class files into your own JAR 解压缩库JAR,然后将类文件打包到您自己的JAR中
  2. Leave the library JARs out of your JAR, and then reference them using the manifest file (just like you did). 将库JAR从JAR中删除,然后使用清单文件引用它们(就像您一样)。

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. JAR文件中的Class-Path清单条目指向文件系统(相对于JAR文件),而不指向嵌入在JAR文件中的文件。

Either unpack the BC jars and add their content to your JAR file or offer the BC jars as separate downloads. 解压缩BC jar并将其内容添加到JAR文件中,或者将BC jar作为单独的下载提供。 You can specify more then one JAR file in the applet tag's archive attribute, by separating them with a comma. 您可以在applet标记的archive属性中指定多个JAR文件,方法是用逗号分隔它们。

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. 由于BC jar是签名的,如果将内容重新打包到您自己的JAR文件中,签名就会丢失,最好的解决方案可能是将它们作为单独的文件提供,并将它们列在archive属性中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM