如何编译具有多个依赖关系(导入和.jar文件)的文件?

huangapple go评论87阅读模式
英文:

How do you compile files with multiple dependencies (imports and .jar files)?

问题

我有以下的目录结构:

如何编译具有多个依赖关系(导入和.jar文件)的文件?

我在编译'models'包中的源文件时遇到了问题,这些文件依赖于src包中的所有其他文件,以及lib中的.jar文件。我应该如何编写类路径(在Mac上)以编译这些模型文件?

<!-- language: none -->

joseph@Josephs-MacBook-Pro models % javac -cp &quot;.:..&quot; NeuralNetworkMultiClass.java
../utils/Metrics.java:4: 错误: 找不到包org.knowm.xchart.style
import org.knowm.xchart.style.AxesChartStyler;
                             ^
../utils/Metrics.java:5: 错误: 找不到包org.knowm.xchart.style
import org.knowm.xchart.style.Styler;
                             ^
../utils/Metrics.java:6: 错误: 找不到包org.knowm.xchart.style.markers
import org.knowm.xchart.style.markers.SeriesMarkers;
                                     ^
../utils/Metrics.java:3: 错误: 找不到包org.knowm.xchart
import org.knowm.xchart.*;
^
../utils/Metrics.java:34: 错误: 找不到符号
        XYChart chart = new XYChartBuilder()
        ^
  符号:   类XYChart
  位置: 类Metrics
../utils/Metrics.java:34: 错误: 找不到符号
        XYChart chart = new XYChartBuilder()
                            ^
  符号:   类XYChartBuilder
  位置: 类Metrics
../utils/Metrics.java:50: 错误: 找不到符号
        XYSeries series = chart.addSeries(seriesName, xData, yData);
        ^
  符号:   类XYSeries
  位置: 类Metrics
../utils/Metrics.java:51: 错误: 找不到符号
        series.setMarker(SeriesMarkers.NONE);
                         ^
  符号:   变量SeriesMarkers
  位置: 类Metrics
../utils/Metrics.java:52: 错误: 找不到符号
        new SwingWrapper&lt;&gt;(chart).displayChart();
            ^
  符号:   类SwingWrapper
  位置: 类Metrics
../utils/Metrics.java:69: 错误: 找不到符号
        ArrayList&lt;XYChart&gt; charts = new ArrayList&lt;&gt;();
                  ^
  符号:   类XYChart
  位置: 类Metrics
../utils/Metrics.java:74: 错误: 找不到符号
        XYChart chart = new XYChartBuilder()
        ^
  符号:   类XYChart
  位置: 类Metrics
../utils/Metrics.java:74: 错误: 找不到符号
        XYChart chart = new XYChartBuilder()
                            ^
  符号:   类XYChartBuilder
  位置: 类Metrics
../utils/Metrics.java:81: 错误: 找不到符号
        XYSeries costA1 = chart.addSeries("Alpha = 1", xData, ySeries[0]);
        ^
  符号:   类XYSeries
  位置: 类Metrics
../utils/Metrics.java:82: 错误: 找不到符号
        XYSeries costA2 = chart.addSeries("Alpha = 0.1" , xData, ySeries[1]);
        ^
  符号:   类XYSeries
  位置: 类Metrics
../utils/Metrics.java:83: 错误: 找不到符号
        XYSeries costA3 = chart.addSeries("Alpha = 0.01", xData, ySeries[2]);
        ^
  符号:   类XYSeries
  位置: 类Metrics
../utils/Metrics.java:84: 错误: 找不到符号
        costA1.setMarker(SeriesMarkers.NONE);
                         ^
  符号:   变量SeriesMarkers
  位置: 类Metrics
../utils/Metrics.java:85: 错误: 找不到符号
        costA2.setMarker(SeriesMarkers.NONE);
                         ^
  符号:   变量SeriesMarkers
  位置: 类Metrics
../utils/Metrics.java:86: 错误: 找不到符号
        costA3.setMarker(SeriesMarkers.NONE);
                         ^
  符号:   变量SeriesMarkers
  位置: 类Metrics
../utils/Metrics.java:90: 错误: 找不到符号
        new SwingWrapper&lt;&gt;(charts).displayChartMatrix();
            ^
  符号:   类SwingWrapper
  位置: 类Metrics
../utils/Metrics.java:108: 错误: 找不到符号
        ArrayList&lt;XYChart&gt; charts = new ArrayList&lt;&gt;();
                  ^
  符号:   类XYChart
  位置: 类Metrics
../utils/Metrics.java:116: 错误: 找不到符号
            XYChart chart = new XYChartBuilder()
            ^
  符号:   类XYChart
  位置: 类Metrics
../utils/Metrics.java:116: 错误: 找不到符号
            XYChart chart = new XYChartBuilder()
                                ^
  符号:   类XYChartBuilder
  位置: 类Metrics
../utils/Metrics.java:123: 错误: 找不到符号
            XYSeries cost = chart.addSeries("training", xData, ySeries[i]);
            ^
  符号:   类XYSeries
  位置: 类Metrics
../utils/Metrics.java:124: 错误: 找不到符号
            XYSeries recall = chart.addSeries("validation", xData, ySeries[i + 1]);
            ^
  符号:   类XYSeries
  位置: 类Metrics
../utils/Metrics.java:125: 错误: 找不到符号
            cost.setMarker(SeriesMarkers.NONE);
                           ^
  符号:   变量SeriesMarkers
  位置: 类Metrics
../utils/Metrics.java:126: 错误: 找不到符号
            recall.setMarker(SeriesMarkers.NONE);
                             ^
  符号:   变量SeriesMarkers
  位置: 类Metrics
../utils/Metrics.java:131: 错误: 找不到符号
        new SwingWrapper&lt;&gt;(charts).displayChartMatrix();
            ^
  符号:
英文:

I have the following directory structure:

如何编译具有多个依赖关系(导入和.jar文件)的文件?

I'm having trouble compiling the source files in the 'models' package, which rely on all other files in packages src as well as the .jar file in lib. How would I write the classpath command to compile these model files (on mac)?

<!-- language: none -->

joseph@Josephs-MacBook-Pro models % javac -cp &quot;.:..&quot; NeuralNetworkMultiClass.java
../utils/Metrics.java:4: error: package org.knowm.xchart.style does not exist
import org.knowm.xchart.style.AxesChartStyler;
                             ^
../utils/Metrics.java:5: error: package org.knowm.xchart.style does not exist
import org.knowm.xchart.style.Styler;
                             ^
../utils/Metrics.java:6: error: package org.knowm.xchart.style.markers does not exist
import org.knowm.xchart.style.markers.SeriesMarkers;
                                     ^
../utils/Metrics.java:3: error: package org.knowm.xchart does not exist
import org.knowm.xchart.*;
^
../utils/Metrics.java:34: error: cannot find symbol
        XYChart chart = new XYChartBuilder()
        ^
  symbol:   class XYChart
  location: class Metrics
../utils/Metrics.java:34: error: cannot find symbol
        XYChart chart = new XYChartBuilder()
                            ^
  symbol:   class XYChartBuilder
  location: class Metrics
../utils/Metrics.java:50: error: cannot find symbol
        XYSeries series = chart.addSeries(seriesName, xData, yData);
        ^
  symbol:   class XYSeries
  location: class Metrics
../utils/Metrics.java:51: error: cannot find symbol
        series.setMarker(SeriesMarkers.NONE);
                         ^
  symbol:   variable SeriesMarkers
  location: class Metrics
../utils/Metrics.java:52: error: cannot find symbol
        new SwingWrapper&lt;&gt;(chart).displayChart();
            ^
  symbol:   class SwingWrapper
  location: class Metrics
../utils/Metrics.java:69: error: cannot find symbol
        ArrayList&lt;XYChart&gt; charts = new ArrayList&lt;&gt;();
                  ^
  symbol:   class XYChart
  location: class Metrics
../utils/Metrics.java:74: error: cannot find symbol
        XYChart chart = new XYChartBuilder()
        ^
  symbol:   class XYChart
  location: class Metrics
../utils/Metrics.java:74: error: cannot find symbol
        XYChart chart = new XYChartBuilder()
                            ^
  symbol:   class XYChartBuilder
  location: class Metrics
../utils/Metrics.java:81: error: cannot find symbol
        XYSeries costA1 = chart.addSeries(&quot;Alpha = 1&quot;, xData, ySeries[0]);
        ^
  symbol:   class XYSeries
  location: class Metrics
../utils/Metrics.java:82: error: cannot find symbol
        XYSeries costA2 = chart.addSeries(&quot;Alpha = 0.1&quot; , xData, ySeries[1]);
        ^
  symbol:   class XYSeries
  location: class Metrics
../utils/Metrics.java:83: error: cannot find symbol
        XYSeries costA3 = chart.addSeries(&quot;Alpha = 0.01&quot;, xData, ySeries[2]);
        ^
  symbol:   class XYSeries
  location: class Metrics
../utils/Metrics.java:84: error: cannot find symbol
        costA1.setMarker(SeriesMarkers.NONE);
                         ^
  symbol:   variable SeriesMarkers
  location: class Metrics
../utils/Metrics.java:85: error: cannot find symbol
        costA2.setMarker(SeriesMarkers.NONE);
                         ^
  symbol:   variable SeriesMarkers
  location: class Metrics
../utils/Metrics.java:86: error: cannot find symbol
        costA3.setMarker(SeriesMarkers.NONE);
                         ^
  symbol:   variable SeriesMarkers
  location: class Metrics
../utils/Metrics.java:90: error: cannot find symbol
        new SwingWrapper&lt;&gt;(charts).displayChartMatrix();
            ^
  symbol:   class SwingWrapper
  location: class Metrics
../utils/Metrics.java:108: error: cannot find symbol
        ArrayList&lt;XYChart&gt; charts = new ArrayList&lt;&gt;();
                  ^
  symbol:   class XYChart
  location: class Metrics
../utils/Metrics.java:116: error: cannot find symbol
            XYChart chart = new XYChartBuilder()
            ^
  symbol:   class XYChart
  location: class Metrics
../utils/Metrics.java:116: error: cannot find symbol
            XYChart chart = new XYChartBuilder()
                                ^
  symbol:   class XYChartBuilder
  location: class Metrics
../utils/Metrics.java:123: error: cannot find symbol
            XYSeries cost = chart.addSeries(&quot;training&quot;, xData, ySeries[i]);
            ^
  symbol:   class XYSeries
  location: class Metrics
../utils/Metrics.java:124: error: cannot find symbol
            XYSeries recall = chart.addSeries(&quot;validation&quot;, xData, ySeries[i + 1]);
            ^
  symbol:   class XYSeries
  location: class Metrics
../utils/Metrics.java:125: error: cannot find symbol
            cost.setMarker(SeriesMarkers.NONE);
                           ^
  symbol:   variable SeriesMarkers
  location: class Metrics
../utils/Metrics.java:126: error: cannot find symbol
            recall.setMarker(SeriesMarkers.NONE);
                             ^
  symbol:   variable SeriesMarkers
  location: class Metrics
../utils/Metrics.java:131: error: cannot find symbol
        new SwingWrapper&lt;&gt;(charts).displayChartMatrix();
            ^
  symbol:   class SwingWrapper
  location: class Metrics
27 errors

答案1

得分: 1

你正在从 projectDir/src/models 执行该命令,但是 NeuralNetworkMultiClass.java 还依赖其他包。

你可以从 projectDir 运行 Java 编译器,并将所有编译后的类文件放在 out 文件夹中:

javac -cp "src:lib/*" -d out src/*/*.java

然后,如果你想运行 NeuralNetworkMultiClass,可以这样在 projectDir 中执行:

java -cp "out:lib/*" models.NeuralNetworkMultiClass

在指定 -cp 标志的文件/文件夹列表时,请参考这里这里关于平台特定内容。

英文:

You're running the command from projectDir/src/models but NeuralNetworkMultiClass.java depends on other packages as well.

You could run the java compiler from projectDir and place all compiled class files inside out:

javac -cp &quot;src:lib/*&quot; -d out src/*/*.java

Then if you, for example, want to run NeuralNetworkMultiClass, you do it from projectDir like so:

java -cp &quot;out:lib/*&quot; models.NeuralNetworkMultiClass

Refer to this and this on platform specifics when specifying a list of files/folders to the -cp flag.

huangapple
  • 本文由 发表于 2020年10月9日 05:58:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/64271216.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定