简体   繁体   English

简单的.jar文件中的NoClassDefFoundError

[英]NoClassDefFoundError in simple .jar file

I'm trying to create a simple .jar file out of my project. 我正在尝试从我的项目中创建一个简单的.jar文件。 The project is made of two .class files - the main class which uses the secondary class to generate a GUI. 该项目由两个.class文件组成 - 使用二级类生成GUI的主类。 The main class is the actual "main" class that runs while the second class is just a class file with it's methods and it's also an extension of JFrame and imports javax.swing and java.awt.event.*. 主类是运行的实际“主”类,而第二类只是带有它的方法的类文件,它也是JFrame的扩展并导入javax.swing和java.awt.event。*。

I use Jar to bundle it all up. 我用Jar把它捆绑起来。 I add a manifest file (with a new line character) which points to the primary file with the main method. 我添加一个清单文件(带有一个新的行字符),该文件使用main方法指向主文件。 The Jar file thus has two .class files and a folder with the manifest.txt in it. 因此,Jar文件有两个.class文件和一个包含manifest.txt的文件夹。 When I use javaw.exe to run it, nothing happens at all. 当我使用javaw.exe运行它时,根本没有任何事情发生。 So I try to run it in the command line and I get a NoClassDefFroundError about the secondary class. 所以我尝试在命令行中运行它,我得到一个关于辅助类的NoClassDefFroundError。

I noticed I get the same kind of error when I try to compile and run the second class in JCreator - no wonder, it doesn't have a main method, it's just a class file. 当我尝试在JCreator中编译并运行第二个类时,我注意到我遇到了同样的错误 - 难怪它没有主方法,它只是一个类文件。 When I run the main file from JCreator, everything works fine. 当我从JCreator运行主文件时,一切正常。

Any ideas? 有任何想法吗?

Looking at your stack trace, I can now see the problem: I can tell you actually have more than two classes: 看看你的堆栈跟踪,我现在可以看到问题:我可以告诉你实际上有两个以上的类:

Caused by: java.lang.ClassNotFoundException: grafPrime$calcButton at 

There's a file named grafPrime$calcButton.class , and it needs to be in the jar file, too. 有一个名为grafPrime$calcButton.class的文件,它也需要在jar文件中。 There may be other such files -- make sure you include all of them! 可能还有其他此类文件 - 请确保包含所有这些文件!

Okay, the problem is that you've not included the anonymous class - you should have a file called grafPrime$calcButton.class , and that's not in your jar file. 好吧,问题是你没有包含匿名类 - 你应该有一个名为grafPrime$calcButton.class的文件,而这不在你的jar文件中。

Basically, compile your code into a clean directory and include all the class files which are generated. 基本上,将代码编译到一个干净的目录中,并包含生成的所有类文件。

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

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