Reputation: 1721
I have a java file Test.java (below) which uses Guava's HashMultiMap (downloaded from http://code.google.com/p/guava-libraries/). I store both .java and .jar file in "C:\Program Files\Java\jdk1.6.0_25\bin" . And then from command prompt, I execute the commands:
javac -cp guava-11.0.2.jar Test.java
and
java -cp guava-11.0.2.jar Test
"javac -cp guava-11.0.2.jar Test.java" is executing and producing a .class file. However,"java -cp guava-11.0.2.jar Test" is not executing and giving following errors. Can anybody help me why this happening or a step by step procedure to run the given code. Thanks.
Error:
Test.java Code:
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
public class Test {
public static void main(String[] args) {
try {
String key = "hello";
Multimap myMap = HashMultimap.create();
myMap.put(key, 1);
myMap.put(key, 5000);
System.out.println(myMap.get(key));
}
catch (Exception e) {
System.out.println(e);
}
}
}
Upvotes: 1
Views: 417
Reputation: 1503749
By putting Guava on the classpath, you've replaced the current directory as the classpath. Do this:
java -cp guava-11.0.2.jar;. Test
;
is used as the path separator on Windows (it would be :
on Unix) and .
is for the current directory. So this basically says: "Run with a classpath of the Guava jar file and the currently directory, and execute the main
method in the class called Test
"
EDIT: I hadn't spotted your second attempt - the problem with that is the use of a colon instead of a semi-colon as the path separator. It would be fine to use .;guava-11.0.2.jar
instead.
Upvotes: 8