开发者

Beginner question about external java libraries

This command compiles:

java开发者_StackOverflow中文版c -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:

  • Setting the classpath (Solaris)
  • Setting the classpath (Windows)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜