简体   繁体   English

在Windows 8上运行jar文件时出现java.lang.NoClassDefFoundError

[英]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. 我猜这是由于supercsv没有正确包含在类路径中。

Please help me fixing this error. 请帮助我解决此错误。

You need to include the path to the CsvPreference class. 您需要包括CsvPreference类的路径。 This is done using the -cp flag. 这是使用-cp标志完成的。

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. 您需要在运行此Java程序之前将super-csv jar和所有必需的jar放入类路径中。 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> 您可以通过设置CLASSPATH=%CLASSPATH%;<path/to/super-csv jar>;<path to other jars individually>使用系统类路径进行设置
  2. You can specify it using -cp Option while executing Java command 您可以在执行Java命令时使用-cp选项指定它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM