Search code examples
javaeclipsejarprogram-entry-pointclassnotfoundexception

Jar file created with Eclipse: Could not find the main class: UI.MainWindow. Program will exit


I have a Java application developed with Eclipse. I have tried to export it as a .jar file, to run it indipendently, but if I try to run it with the command

java -jar application.jar

I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/data/xy/XYDataset
 Caused by: java.lang.ClassNotFoundException: org.jfree.data.xy.XYDataset
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccesController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$%AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)

Could not find the main class: UI.MainWindow. Program will exit

Currently, the main class is MainWindow.class. It contains a public static void main(String[] args) method. I have checked the manifest.mf file and it seems correct:

  Manifest-Version: 1.0
  Main-Class: UI.MainWindow

I am using a Eclipse IDE for Java Developers version: Helios Release, on a 64-bit Windows 2008 system.

What could I do? How could I solve this? What's the sense of the org/jfree/data/xy/XYDataset error?

Thanks


Solution

  • This is usually a case that occurs when one or more of your required dependency jar files are not included on your class path, and from the MANIFEST snippet you included, it seems this is your problem.

    On another note, you might wanna use the Export Runnable Jar feature, this guarantees that your exported jar will work, given that your Runtime Configuration used as template for exporting this jar is proper.