代碼顯示了-cp扳機,但沒有運行編譯。顯然,它找不到HashMultimap。類路徑問題?Java:如何使用第三方庫?
$ javac -cp google-collect-1.0.jar MultiThing.java
$ java -cp google-collect-1.0.jar MultiThing
Exception in thread "main" java.lang.NoClassDefFoundError: MultiThing
Caused by: java.lang.ClassNotFoundException: MultiThing
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
Could not find the main class: MultiThing. Program will exit.
$ cat MultiThing.java
import java.io.*;
import java.util.*;
import com.google.common.annotations.*;
import com.google.common.collect.*;
public class MultiThing {
public static void main(String[] args) {
Multimap<String, String> wordToFiles = HashMultimap.create();
wordToFiles.put("first", "HELLO");
wordToFiles.put("first", "HALLO");
for (String thing : wordToFiles.get("first")){
System.out.println(thing);
}
}
}
$ ls
google-collect-1.0.jar MultiThing.class com MultiThing.java
將源發佈到您的multitest。 Java在這裏作爲你原來的問題的更新 – 2010-04-05 17:53:03