简体   繁体   中英

Running a java program, having external jar dependency in a batch file

I tried googling a lot but couldnt get a proper working solution .. directory consists of all java files and external jarfile(google.guava.jar).. i want to execute it in a batch file.. i have tried a lot of things...but still says deffclasserror.. can anyone help me out on how to make it work...(Windows).. Structure looks like this:

Folder
--------jar file
--------java file
--------bat file

set path="C:\Program Files (x86)\Java\jdk1.8.0_73\bin"

javac -cp google.guava.jar convertohash
javac FinalOutput.java

java convertohash
java FinalOutput

pause

Try this:

"C:\Program Files (x86)\Java\jdk1.8.0_73\bin\java" -cp %YOUR_CLASSPATH%;%YOUR_CLASSPATH_REPORTS%;%EXTRA_LIB% -Djava.library.path=./dll your.main.class

Before this line you need to set up your YOUR_CLASSPATH your YOUR_CLASSPATH_REPORTS and EXTRA_LIB with = and separating the concurrences with ";" (without the ""). For example:

SET EXTRA_LIB=.\\lib\\mysql-connector-java.jar;.\\lib\\anotherlibrary.jar; etc

Being the "lib" folder the one were you store your libraries, the route doesn't stricly needs to be the one shown on the example just put the one were you store your libraries (if you are using some ofc).

Also keep in mind that if you are going to use this bat in several machines they must have the same jdk installed and on the same route specified or you'll need to change it manually because the application wont launch.

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