小编典典

从Bat文件执行Java时包含Jar

java

我想从bat文件执行Java类,它包括的用法opencsv.jar。下面是代码:

@echo off    
set path=%PATH%;C:\Program Files (x86)\Java\jdk1.6.0\bin    
javac -cp opencsv.jar ArbitrageUsingThread.java    
java ArbitrageUsingThread

运行它时出现以下错误。我认为“包含”存在opencsv.jar任何问题,有人可以帮助我吗?

Error
Exception in thread "main" java.lang.NoClassDefFoundError: au/com/bytecode/openc
sv/CSVWriter
        at ArbitrageUsingThread.main(ArbitrageUsingThread.java:67)
Caused by: java.lang.ClassNotFoundException: au.com.bytecode.opencsv.CSVWriter
        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)
        ... 1 more

阅读 307

收藏
2020-11-26

共1个答案

小编典典

java类似于javacclasspath。

在Linux下:

java -cp opencsv.jar:. ArbitrageUsingThread

在Windows下:

java -cp opencsv.jar;. ArbitrageUsingThread
2020-11-26