简体   繁体   English

Eclipse可以编译但不能在命令行中进行编译(javac)

[英]Eclipse can compile but not in command line(javac)

I'd like to know the way to compile a project which has a dependency. 我想知道编译具有依赖项的项目的方法。

package a;
import b.B;
class A{
    B b;
}
package b;
import a.A;
class B{
    A a;
}

I have a project which has a dependency like the one seen above. 我有一个项目,该项目具有上面所见的依赖项。

I tried to compile with javac (in jdk ). 我试图用javac (在jdk )。 I've already used the -classpath option, but it doesn't work. 我已经使用过-classpath选项,但是它不起作用。

I heard Apache Ant supply this and maybe eclipse uses it. 我听说Apache Ant提供了它,也许eclipse会使用它。 So I think there is no reason that it isn't possible only with java compiler. 因此,我认为没有理由仅使用Java编译器是不可能的。

I'd like to know the way to compile this with javac (in command line) and, if you know, how apache ant and eclipse work together to compile. 我想知道使用javac (在命令行中)进行编译的方法,并且,如果您知道的话, apache anteclipse如何一起工作进行编译。 Could you tell me the reason?? 你能告诉我原因吗?

I wonder how can Eclipse compile your code. 我想知道Eclipse如何编译您的代码。 Mine can only if I modify the class visibility to public: 仅当我将班级公开程度修改为公开时​​,我的人才可以:

a/A.java A / A.java

package a;

import b.B;

public class A {
    B b;
}

b/B.java b / B.java

package b;

import a.A;

public class B {
    A a;
}

Compiling from the command line is easy then: 从命令行进行编译很容易:

javac a/A.java b/B.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM