2013-03-29 80 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

相關問題