i am developing a program,for that want to use more than one jar(Example servlet.jar and mysql.jar) i know how to import them in using Eclipse IDE. but not in cmd prompt. Can anybody help me for this thanks in advance...
-
Check-out this http://stackoverflow.com/questions/219585/setting-multiple-jars-in-java-classpath – Miko Jul 29 '14 at 06:25
5 Answers
For multiple jars you can do
java -cp "path1/servlet.jar;path2/mysql.jar" yourPackage.Class
Or put all jars in one folder (let it be path1/lib) and do something like following
java -cp "path1/lib/*" yourPackage.Class
Note : classpath wildcards can be used only in Java 6 or later.

- 66,731
- 38
- 279
- 289
-
Please note that the syntax is error prone. The "path1/lib/*" will work, something like "path/lib/MySQL*" probably not. Also I mean to remember that the seperator between the JARs is platform depending (not 100% sure). – Arne Deutsch Jul 29 '14 at 06:32
-
thanks for a clarification ;(semi colon) only used to seperate 2 jars, am i correct. – Saravanamanikandan Jul 29 '14 at 06:44
-
Nope any two path.. not just the jars. You can include two directories as well. – Aniket Thakur Jul 29 '14 at 06:45
-
In similar way we can add several path seperated by ;(semi colon) in value field for the classpath variable in environmental variable also na – Saravanamanikandan Jul 29 '14 at 06:53
-
If you want to create a new classpath, write this:
set CLASSPATH=classpath1;
You can see all your classpaths if you type only this:
set

- 319
- 3
- 12
ClassPath set through command prompt will work only for current cmd window. Once you close it and open a new cmd window it will not work. Rather than setting classpath from command prompt, keep related paths to system properties:
For windows:
go to My Computer--> Properties--> Advance System Settings--> Environment Variables--> CLASSPATH--> put your path like this--> path1;path2;path3;. Don't forget to keep . (DOT) at the end.

- 3,472
- 2
- 18
- 28
-
oh thanks Shailesh, Your syntax little bit confusing me can give a example. – Saravanamanikandan Jul 29 '14 at 06:37
-
you can set your class path using cmd prompt like :-
set classpath=(dir of classpath1);(dir of classpath2);(
dir of class path3
);%CLASSPATH%

- 1,530
- 1
- 11
- 23
In enviorment variables , make a new variable named classpath and in value field write as much path you want but seperate them by semicolon.

- 390
- 4
- 14