编程语言
首页 > 编程语言> > 从Bat文件执行Java时包含Jar

从Bat文件执行Java时包含Jar

作者:互联网

我想从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

解决方法:

Java与类路径的javac类似.

在Linux下:

java -cp opencsv.jar:. ArbitrageUsingThread

在Windows下:

java -cp opencsv.jar;. ArbitrageUsingThread

标签:java,batch-file,classpath
来源: https://codeday.me/bug/20191011/1890206.html