Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including jar files in class path

I m running a java program from a batch file which refences some external jar files .How do i include those jar files in my batch file.Please help

like image 455
Wasim Wani Avatar asked Nov 10 '11 19:11

Wasim Wani


People also ask

Where do I put JAR files?

As of Java 6, extension JAR files may also be placed in a location that is independent of any particular JRE, so that extensions can be shared by all JREs that are installed on a system. It says that for Windows you should place your extensions here %SystemRoot%\Sun\Java\lib\ext .

How do I find the classpath of a JAR file?

To check our CLASSPATH on Windows we can open a command prompt and type echo %CLASSPATH%. To check it on a Mac you need to open a terminal and type echo $CLASSPATH.

How do I run a JAR file in main class?

To run an application in a nonexecutable JAR file, we have to use -cp option instead of -jar. We'll use the -cp option (short for classpath) to specify the JAR file that contains the class file we want to execute: java -cp jar-file-name main-class-name [args …]


1 Answers

Look at the Sun's official documentation: Setting the class path to understand your options.

A quick way would be just to include your JAR(s) after the -cp:

on Windows

java -cp C:\java\MyClasses\myclasses.jar;C:\java\MyClasses\myclassesAnother.jar utility.myapp.Cool

on Linux/Unix

java -cp /opt/thirdparty/myclasses.jar:/opt/thirdparty/myclassesAnother.jar utility.myapp.Cool
like image 114
tolitius Avatar answered Nov 07 '22 09:11

tolitius