Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add multiple jar(s) to classpath?

Tags:

java

classpath

I am having more than 25 jar files how to add all of them in a classpath?

like image 249
Lalchand Avatar asked Aug 02 '10 12:08

Lalchand


People also ask

How do I add a classpath to a class in Java?

Include all the directories which contain . class files and JAR files when setting the CLASSPATH. You need to load a class that is not present in the current directory or any sub-directories. You need to load a class that is not in a location specified by the extensions mechanism.

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.


2 Answers

If all the jar files are in the same folder, as of jdk6, Java supports classpath wildcards. http://download.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html

So you can use something like,

/path/to/jar/*

Also consider having a separate classpath for each project.

like image 103
rags23 Avatar answered Oct 16 '22 23:10

rags23


Separate them with a colon / semicolon (: / ;) on *nix / win

But it would be way easier to use an IDE (Eclipse, NetBeans) to handle the classpath for you.

like image 32
Bozho Avatar answered Oct 17 '22 00:10

Bozho