Vinay Chhabra
Vinay Chhabra

Reputation: 59

Including Jar while executing Java from Bat file

I want to execute a Java class from a bat file and it include usage of opencsv.jar. Below is the code:

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

I am getting the following error when running it. I think there is some problem with including opencsv.jar Can anyone help me with this?

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

Upvotes: 2

Views: 787

Answers (1)

user180100
user180100

Reputation:

java is similar to javac for classpath.

Under linux:

java -cp opencsv.jar:. ArbitrageUsingThread

Under windows:

java -cp opencsv.jar;. ArbitrageUsingThread

Upvotes: 2

Related Questions