jar里面的NoClassDefFoundError [英] NoClassDefFoundError inside jar
问题描述
我有一个类,它位于一个名为com.toptur.sysTray的包中,它只是加载系统托盘,它不使用任何外部包。我创建一个SysTray对象来安装系统托盘。 Everthing构建良好。我可以从命令行运行应用程序并安装systray。但是,当我尝试从类文件创建一个jar并运行它时,我得到NoClassDefFoundError。
I have a class that that sits in a package called com.toptur.sysTray all it does is load system tray it does not use any external packages. i create a SysTray object to install the system tray. Everthing builds fine. i can run the application from command line and systray gets installed. But when i try to create a jar from the class files and run it i get NoClassDefFoundError.
包及其类文件在我的应用程序不使用ant外部的jar中罐子。只是java提供的类。
Package and its class files are in the jar my application does not use ant external jars. just classes provied by java.
如果从jar中构建一个.exe文件,它会再次开始工作而不会出现任何错误。
And if build a .exe file out of the jar, it starts to work again without any errors.
我如何追踪这个?
<target name="jar" depends="">
<jar destfile="build/toptur.jar" >
<manifest>
<attribute name="Built-By" value="Toptur"/>
<attribute name="Main-Class" value="gotacan"/>
</manifest>
<fileset dir="build">
<include name="**/*.class"/>
<include name="**/*.png"/>
<exclude name="**/*.jar"/>
</fileset>
</jar>
我从中创建jar文件使用上述代码的蚂蚁目标。驱动程序不在包中。它位于gotacan.java
i create the jar file from a ant target using above code. driver program is not in a package. its located in gotacan.java
我使用java -jar toptur.jar运行它
I run it using java -jar toptur.jar
程序的其余部分当我尝试使用该软件包时,它只会引发异常。
rest of the program works it only throws exception when i try to use that package.
推荐答案
Class not Found Exception应该提到类的名称它正在寻找。
The Class not Found Exception should mention the name of the class it is looking for.
由于你在类路径上只有jar,它应该在jar中,但事实并非如此。找出原因,可能的原因:
Since you have only the jar on the classpath it should be in the jar, but it isn't. Figure out why, possible reasons:
- 当ant构建软件包时,类文件不在它所属的位置
- 表示包名称的目录结构不是以所有其他类为根的所在的根目录
- 类文件所属的位置不包含在要放入的文件列表中jar by ant。
祝你好运
注意:罐子只是拉链具有态度的文件,因此您可以使用任何zip程序来检查实际存在的文件。
Note: jars are just zip files with an attitude, so you can use any zip-program to check what files are actually in there.
这篇关于jar里面的NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!