简体   繁体   中英

Beginner question about external java libraries

This command compiles:

javac -classpath google-collections.jar Test.java

What's the command to run Test.class?

java -classpath google-collections.jar:. Test

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

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM