简体   繁体   中英

NoClassDefFoundError in simple .jar file

I'm trying to create a simple .jar file out of my project. The project is made of two .class files - the main class which uses the secondary class to generate a 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.*.

I use Jar to bundle it all up. I add a manifest file (with a new line character) which points to the primary file with the main method. The Jar file thus has two .class files and a folder with the manifest.txt in it. When I use javaw.exe to run it, nothing happens at all. So I try to run it in the command line and I get a NoClassDefFroundError about the secondary class.

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. When I run the main file from JCreator, everything works fine.

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. 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.

Basically, compile your code into a clean directory and include all the class files which are generated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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