2013-03-29 134 views
0

我很新的Java编程和我想的jar添加到类路径是这样的:如何将我的jar添加到Java编译路径?

javac -classpath ~/Downloads/algs4.jar. ThreeSum.java 

但我依然得到了异常,如:

ThreeSum.java:38: error: cannot find symbol 
         StdOut.println(a[i] + " " + a[j] + " " + a[k]); 
         ^
    symbol: variable StdOut 
    location: class ThreeSum 
ThreeSum.java:62: error: cannot find symbol 
     int[] a = In.readInts(args[0]); 
       ^
    symbol: variable In 
    location: class ThreeSum 
ThreeSum.java:64: error: cannot find symbol 
     Stopwatch timer = new Stopwatch(); 
     ^
    symbol: class Stopwatch 
    location: class ThreeSum 
ThreeSum.java:64: error: cannot find symbol 
     Stopwatch timer = new Stopwatch(); 
          ^
    symbol: class Stopwatch 
    location: class ThreeSum 
ThreeSum.java:66: error: cannot find symbol 
     StdOut.println("elapsed time = " + timer.elapsedTime()); 
     ^
    symbol: variable StdOut 
    location: class ThreeSum 
ThreeSum.java:67: error: cannot find symbol 
     StdOut.println(cnt); 
     ^
    symbol: variable StdOut 
    location: class ThreeSum 
6 errors 

我米here

+0

为什么downvote ??? – sriram

+0

“安装教科书库”一节(http://algs4.cs.princeton.edu/code/#classpath)解释了如何做到这一点。 – Joe

回答

2

看起来你需要以及下载这个JAR:http://introcs.cs.princeton.edu/java/stdlib/

他们没有一个包结构,所以解压在同一目录下的所有内容:

jar xvf stdlib.jar 
jar xvf algs4.jar 

然后编译:

javac -classpath . ThreeSum.java 
+1

或者,为了让它们放在罐子里,'-classpath。:stdlib.jar:algs4.jar'。 – Joe

+0

@Joe是的,你说得对。 'jar xvf'不是必需的。 – whiskeyspider

1

试图节目你可能想~/Downloads/algs4.jar.为类路径是在Linux上~/Downloads/algs4.jar:.~/Downloads/algs4.jar;.上Windows`

+0

我试过了。同样的错误。 – sriram

相关问题