【问题标题】:How do I add my jar to Java compilation path?如何将我的 jar 添加到 Java 编译路径?
【发布时间】:2013-03-29 04:12:26
【问题描述】:

我对 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

我正在尝试here的程序

【问题讨论】:

标签: java class jar


【解决方案1】:

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

它们没有包结构,因此将所有内容解包到同一目录中:

jar xvf stdlib.jar
jar xvf algs4.jar

然后编译它:

javac -classpath . ThreeSum.java

【讨论】:

  • 或者,把它们放在罐子里,-classpath .:stdlib.jar:algs4.jar
【解决方案2】:

您可能希望 ~/Downloads/algs4.jar. 为该类路径在 Linux 上为 ~/Downloads/algs4.jar:. 或在 Windows 上为 ~/Downloads/algs4.jar;.`

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 2020-06-27
    • 2011-02-13
    • 2013-08-27
    • 2012-06-14
    • 2018-10-18
    相关资源
    最近更新 更多