简体   繁体   English

Javac的Makefile编译问题

[英]Makefile compilation issue with javac

I have a problem with a makefile. 我的makefile有问题。 I have three classes. 我有三节课。 They do pretty simple stuff. 他们做的很简单。 One does an addition on a subtraction, and the last one will instantiate the two and simply print the resulted addition and subtraction. 一个对减法进行加法,最后一个将实例化这两个,并简单地打印结果加法和减法。

Now when I create my makefile, I compile my Plus.java and my Minus.java but don't know how to compile the main class because it depends on the previous two. 现在,当我创建我的makefile时,我将编译Plus.java和Minus.java,但不知道如何编译主类,因为它取决于前两个。 I want to compile and run it from the makefile if it's possible. 如果可能,我想从makefile编译并运行它。

I get the above results when I try to run make: 当我尝试运行make时,我得到了以上结果:

javac -g Plus.class Minus.class
javac: invalid flag: Plus.class
Usage: javac <options> <source files>
use -help for a list of possible options
make: *** [Operation.class] Error 2

I don't know how to proceed; 我不知道如何进行; please forgive me if my question is to simple but I am new working with these stuff. 如果我的问题很简单,请原谅我,但是我是这些东西的新手。 I've searched many sites but with no answer. 我搜索了许多站点,但没有答案。

Here is my Makefile: 这是我的Makefile:

JCC = javac

JCR = java

JFLAGS = -g

default: Operation.class

Plus.class: Plus.java
    $(JCC) $(JFLAGS) Plus.java

Minus.class: Minus.java
    $(JCC) $(JFLAGS) Minus.java

Operation.class: Operation.class
    $(JCC) $(JFLAGS) Operation.class  

run: Operation.class
    $(JCR) Operation.class

clean:
    $(RM) *.class

You need to pass the names of source files to javac: 您需要将源文件的名称传递给javac:

javac -g Plus.java

A better option is possibly: 更好的选择可能是:

javac -g *.java

Very few people in the Java world invoke javac directly or use makefiles. Java世界中很少有人直接调用javac或使用makefile。 Most people use an IDE when developing: 大多数人在开发时都使用IDE:

Eclipse: http://www.eclipse.org Eclipse: http//www.eclipse.org
Netbeans: http://www.netbeans.org Netbeans: http//www.netbeans.org

And then a more comprehensive build tool for final / automated builds: 然后是用于最终/自动构建的更全面的构建工具:

Ant: http://ant.apache.org/ 蚂蚁: http//ant.apache.org/
Maven: http://maven.apache.org/ Maven: http//maven.apache.org/

Both of those could be invoked from make, or indeed invoke make themselves, in order to integrate with your existing build system. 两者都可以从make调用,或者实际上是自己调用make,以便与您现有的构建系统集成。

EDIT: It seems you have a makefile issue. 编辑:似乎您有一个makefile问题。 See if this works: 查看是否可行:

JCC = javac
JCR = java
JFLAGS = -g

all:
[TAB]$(JCC) $(JFLAGS) *.java

run:
[TAB]$(JCR) Operation

clean:
[TAB]$(RM) *.class

Replace [TAB] with an actual tab character - as you probably know this is incredibly important in make! 用实际的制表符替换[TAB]-您可能知道这在make中非常重要!

您需要运行javac -g Plus.java Minus.java(而不是.class)

Try this. 尝试这个。 Alas, managing Java class dependencies is a pain using make (been there done that in relatively large projects), so you should still seriously consider using Ant or some other appropriate tool. las,使用make来管理Java类依赖关系是一件痛苦的事情(在相对较大的项目中就已经做到了),因此您仍然应该认真考虑使用Ant或其他一些合适的工具。

JCC = javac

JCR = java

JFLAGS = -g

default: Operation.class

Plus.class: Plus.java
            $(JCC) $(JFLAGS) Plus.java

Minus.class: Minus.java
             $(JCC) $(JFLAGS) Minus.java

Operation.class: Operation.java Plus.class Minus.class
                $(JCC) $(JFLAGS) Operation.java 

run: Operation.class
    $(JCR) Operation.class

clean: $(RM) *.class

I solved it. 我解决了 It was a problem with the packages. 软件包有问题。 I edited my files in netbeans and remained: 我在netbeans中编辑了文件,并保持:

package operations 包装操作

to every one of them 给他们每个人

so I got Operation to compile but now it didn't run 所以我可以编译Operation,但是现在没有运行

Silly problem.... 愚蠢的问题。

JCC = javac

JCR = java

JFLAGS = -g

default: Operation.class Plus.class Minus.class

Plus.class: Plus.java
    $(JCC) $(JFLAGS) Plus.java

Minus.class: Minus.java
    $(JCC) $(JFLAGS) Minus.java

Operation.class: Operation.java Plus.java Minus.java
    $(JCC) $(JFLAGS) Operation.java  Plus.java Minus.java

run:
    $(JCR) Operation

clean:
    $(RM) *.class

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

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