java applet中带有外部jar的java.lang.NoClassDefFoundError

时间:2011-08-17 15:58:51

标签: java eclipse jar applet

我有一个Java applet,它使用多个外部jar。在Eclipse中,项目运行良好。当它被导出并运行嵌入HTML文件时,我得到22个类似于..

的运行时异常
java.lang.RuntimeException: java.lang.NoClassDefFoundError: 
    mil/dcgs/mdf/webservice/ddms/ingest/CatalogIngestService

..各种课程。当我打开导出的jar时,我看到没有.class文件或来自外部jar的任何其他痕迹。

HTML

HTML是:

<html> 
<head> 
<title>DIB Applet</title> 
</head> 
<body> 
<applet 
    code="org.mitre.inception.Main.class" 
    archive="inception.jar" 
    WIDTH = "1020" 
    HEIGHT = "500">
Applet
</applet> 
</body> 
</html> 

的.classpath

我的.classpath如下所示。

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="lib" path="C:/Users/myUserName/Desktop/jars/dcgs-util.jar"/>
    <!-- more jars removed for space reasons as they look the same as above -->
    <classpathentry kind="output" path="bin"/>
</classpath>

2 个答案:

答案 0 :(得分:1)

classpath提及dcgs-util.jar。这可能应该列在archive元素的applet属性中。也许是这样的事情:

<html> 
<head> 
<title>DIB Applet</title> 
</head> 
<body> 
<applet 
    code="org.mitre.inception.Main.class" 
    archive="inception.jar,jars/dcgs-util.jar" 
    WIDTH = "1020" 
    HEIGHT = "500">
Applet
</applet> 
</body> 
</html> 

假设inception.jar与HTML位于同一目录中,dcgs-util.jar位于目录的jars子目录中。 HTML所在的位置。

答案 1 :(得分:0)

尝试使用以下类路径。我只是改变了jar文件的顺序。

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="lib" path="C:/Users/myUserName/Desktop/jars/dcgs-util.jar"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>    
    <!-- more jars removed for space reasons as they look the same as above -->
    <classpathentry kind="output" path="bin"/>
</classpath>