My code compiles correctly in Eclipse, as well as runs. Before I added a piece of code I could also successfully make a jar file by doing:
jar cvfm Manifest.txt <Classes>
then I added this to my code in the constructor:
addWindowFocusListener(new WindowAdapter() {
public void windowGainedFocus(WindowEvent e) {
JFrame window = (JFrame) e.getSource();
window.toBack();
}});
When I try to create a new jar file and run it, I receive the NoClassDefError with the error line pointing to that code. To be specific, I got this:
Exception in thread "main" java.lang.NoClassDefFoundError: BinaryClock$1
at BinaryClock.<init>(BinaryClock.java:55)
BinaryClock being my main class and line 55 being the first line of the code from above. I don’t understand why it makes BinaryClock$1, then gives me the error on it.
If more code or information is needed, let me know. I didn’t want to paste my entire source code if it wasn’t needed.
The
BinaryClock$1.classfile will contain the anonymous inner class created for yourWindowAdapterin the code you’ve shown. You should include that file in the jar file.Basically, you should build into a clean directory, and include everything in that directory in your jar file. Don’t try to be selective about it – if a file is being produced by the compiler, there’s a good reason for it.