简体   繁体   中英

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.

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 

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

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