Proyb2
Proyb2

Reputation: 993

Java: tips to add classpath

I have both a library.jar and program.jar in Java folder.

What is the correct command line to run? One method I tried is:

C:>java -cp c:\java\library.jar;.\java\program.jar program [param]

Upvotes: 1

Views: 245

Answers (3)

dogbane
dogbane

Reputation: 274562

Classpath entries can also contain the wildcard(*) character. For example, the class path entry C:\java\* specifies all JAR files in the C:\java directory and will be expanded into C:\java\library.jar;C:\java\program.jar.

Upvotes: 0

duffymo
duffymo

Reputation: 308753

If you intend for your program.jar to be an executable JAR, you'll have to run it this way (and read this):

java -jar program.jar

Upvotes: 0

aioobe
aioobe

Reputation: 420951

Try

java -cp c:\java\library.jar;.\java\program.jar package.the.MainClass [param]

From http://download.oracle.com/javase/1.3/docs/tooldocs/win32/classpath.html

Folders and archive files

When classes are stored in a directory (folder), like

c:\java\MyClasses\utility\myapp, then

the class path entry points to the directory that contains the first element of the package name. (in this case,C:\java\MyClasses, since the package name is utility.myapp.)

But when classes are stored in an archive file (a .zip or .jar file) the class path entry is the path to and including the .zip or .jar file. For example, to use a class library that is in a .jar file, the command would look something like this:

C:> java -classpath C:\java\MyClasses\myclasses.jar utility.myapp.Cool

Multiple specifications

To find class files in the directory C:\java\MyClasses as well as classes in C:\java\OtherClasses, you would set the class path to:

C:> java -classpath C:\java\MyClasses;C:\java\OtherClasses ...

Note that the two paths are separated by a semicolon.

Upvotes: 3

Related Questions