簡體   English   中英

如何將jar添加到Java編譯路徑?

[英]How do I add my jar to Java compilation path?

我是Java編程的新手,我正在嘗試將jar添加到類路徑中,如下所示:

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

我正在從這里嘗試程序

看來您也需要下載此JAR: http : //introcs.cs.princeton.edu/java/stdlib/

它們沒有包結構,因此請解壓縮同一目錄中的所有內容:

jar xvf stdlib.jar
jar xvf algs4.jar

然后編譯它:

javac -classpath . ThreeSum.java

您可能需要~/Downloads/algs4.jar. ~/Downloads/algs4.jar:.路徑為~/Downloads/algs4.jar:. 在Linux上或~/Downloads/algs4.jar;. 在Windows上

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM