Suvendu
Suvendu

Reputation: 19

java.lang.NoClassDefFoundError while running a jar file on windows 8

When I am giving the following command

java -Xmx1500m -jar myApp.jar %1 %2 %3 %4 %5 %6 %7 %8 %9 

I am getting the following error.

Throwable Error: java.lang.NoClassDefFoundError: org/supercsv/prefs/CsvPreference
Exception in thread "main" java.lang.Error: java.lang.NoClassDefFoundError: org/supercsv/prefs/CsvPreference
        at bc.c.Util.process(Util.java:135)
        at bc.m.TabularReader$CSVReader.<init>(TabularReader.java:68)
        at bc.m.TabularReader.<init>(TabularReader.java:37)
        at bc.c.Spread2db.main(Spread2db.java:244)
Caused by: java.lang.NoClassDefFoundError: org/supercsv/prefs/CsvPreference
        at bc.m.TabularReader$CSVReader.<init>(TabularReader.java:64)
        ... 2 more
Caused by: java.lang.ClassNotFoundException: org.supercsv.prefs.CsvPreference
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.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)
        ... 3 more

I guess that this is due to the supercsv which is not getting included properly in the class path.

Please help me fixing this error.

Upvotes: 0

Views: 1204

Answers (2)

Sanjeev
Sanjeev

Reputation: 9946

You need to put super-csv jar and all the required jars in your class path before running this java program. you have two options to do that:

  1. You can set it using system classpath by set CLASSPATH=%CLASSPATH%;<path/to/super-csv jar>;<path to other jars individually>
  2. You can specify it using -cp Option while executing Java command

Upvotes: 1

Keppil
Keppil

Reputation: 46219

You need to include the path to the CsvPreference class. This is done using the -cp flag.

Try

java -Xmx1500m -cp pathToCsvPreference -jar myApp.jar %1 %2 %3 %4 %5 %6 %7 %8 %9 

Upvotes: 1

Related Questions