1

如何在 CLASSPATH 中使用 google-collections 在终端中使用 javac 编译代码?

尝试在终端中使用 javac 编译的代码示例(在 Eclipse 中工作)

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
public class Locate {
   ...
   BiMap<MyFile, Integer> rankingToResult = HashBiMap.create();
   ...
}

在终端编译

src 288 % javac Locate.java 
Locate.java:14: package com.google.common.collect does not exist
import com.google.common.collect.BiMap;
                                ^
Locate.java:15: package com.google.common.collect does not exist
import com.google.common.collect.HashBiMap;
                                ^
Locate.java:153: cannot find symbol
symbol  : class BiMap
location: class Locate
        BiMap<MyFile, Integer> rankingToResult = HashBiMap.create();
        ^
Locate.java:153: cannot find symbol
symbol  : variable HashBiMap
location: class Locate
        BiMap<MyFile, Integer> rankingToResult = HashBiMap.create();
                                                 ^
4 errors

我的类路径

src 289 % echo $CLASSPATH 
/u/1/bin/javaLibraries/google-collect-1.0.jar
4

1 回答 1

4
  javac -cp /u/1/bin/javaLibraries/google-collect-1.0.jar Locate.java

或者,Java 6 中的新功能,让它扫描目录

  javac -cp '/u/1/bin/javaLibraries/*' Locate.java
于 2010-03-31T00:56:05.567 回答