3

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

Sumit Singh
  • 15,743
  • 6
  • 59
  • 89
DavideChicco.it
  • 3,318
  • 13
  • 56
  • 84

5 Answers5

5

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.

Sumit Singh
  • 15,743
  • 6
  • 59
  • 89
Waleed Almadanat
  • 1,027
  • 10
  • 24
  • Thanks: I did not know about the "Export as Runnable JAR file" on Eclipse. I've tried it, fixed some configuration details, and everything works fne! Many ultra-super-thanks from Italy to Jordan! ^_^ – DavideChicco.it Jan 16 '13 at 12:08
  • Super-awesome-welcome from Jordan to Italy, don't mention it @DavideChicco.it ;) Eclipse is a great IDE in my opinion (I also like netBeans for some of it's features such as the Profiling feature). So, I encourage you to explore more of it! – Waleed Almadanat Jan 16 '13 at 12:15
2

2 things you could do is

  1. Launch the java application with dependency jar in class path as below.
    java -cp jfreechart-1.x.x.jar -jar application.jar

  2. Add Classpath option with in your MANIFEST.MF as below
    Manifest-Version: 1.0
    Main-Class: UI.MainWindow Class-Path: < PATH to the jfreechart-1.x.x.jar >

Sumit Singh
  • 15,743
  • 6
  • 59
  • 89
Syam
  • 1,202
  • 11
  • 23
  • The (1) option got the same error as before. The (2) option give a slightly changed error: now the console says `Exception in thread "main" java.lang.NoClassDefFoundError: UI/MainWindow`, and the rest is the same. Thanks anyway – DavideChicco.it Jan 16 '13 at 11:32
  • Just explore(open) the jar file whether it has really the mentioned class in it. – Syam Jan 16 '13 at 11:37
  • with in application.jar Under "UI" folder MainWindow.class file should be present. – Syam Jan 16 '13 at 11:45
0

It means that in your code main() method - org/jfree/data/xy/XYDataset is not found

Possible reason is org.jfree library jar is not present in your classpath

TheWhiteRabbit
  • 15,480
  • 4
  • 33
  • 57
  • I'll check now this library, but anyway my main class in NOT in the jfree package, it is in my MainWindow class... – DavideChicco.it Jan 16 '13 at 10:02
  • yes , your main class is trying to access a Class `XYDataset` which is part of JFree chart library, which its unable to locate because its not available in classpath – TheWhiteRabbit Jan 16 '13 at 10:04
  • I've repeated the export operation, by adding the \libraries\ folder this time. But the problem remains... :-( – DavideChicco.it Jan 16 '13 at 10:12
  • look for the ways to include .jar files in classpath , when running an executable jar file for [example](http://stackoverflow.com/questions/6021800/generating-an-executable-jar-with-dependencies-external-jars-in-eclipse) or [this](http://stackoverflow.com/questions/6817651/bundling-jar-dependencies-with-executable-jar-ber-jar-from-command-line) – TheWhiteRabbit Jan 16 '13 at 11:30
0

1.You can try to put library into jdk class path
2.Then export jar and run

lib path will be
$JDK_HOME\jre\lib\ext
$JDK_HOME is your jdk installation root path
Sumit Singh
  • 15,743
  • 6
  • 59
  • 89
Mohammod Hossain
  • 4,134
  • 2
  • 26
  • 37
0

I got similar to this with the Google Web Toolkit sample web app creation. This was erroring becuase the Java compiler was set to 1.6 and GWT v2.6 requires jdk 1.7 + . I switched the jdk and version. The GWT was able to compile.

iowatiger08
  • 1,892
  • 24
  • 30