gamedevv
gamedevv

Reputation: 315

Beginner question about external java libraries

This command compiles:

javac -classpath google-collections.jar Test.java

What's the command to run Test.class?

Upvotes: 2

Views: 123

Answers (2)

coobird
coobird

Reputation: 160954

The following will have the current directory and the google-colletions.jar as the classpath:

java -cp .;google-collections.jar Test

This will run the main method in the Test class with the following signature:

public static void main(String[])

Note:

As noted by Paul Tomblin in the comments, the separator character for the classpath is different depending on the platform on which javac is run on.

For Solaris/Linux (and apparently Mac OS), the separator character is a colon (:), while on Windows, it is a semi-colon (;).

Reference:

Upvotes: 3

ZoogieZork
ZoogieZork

Reputation: 11279

java -classpath google-collections.jar:. Test

The ":." adds the current directory to the classpath so java can find Test.class

Upvotes: 3

Related Questions