javac的Makefile编译问题

发布于 2024-09-01 06:25:09 字数 854 浏览 4 评论 0原文

我的 makefile 有问题。我有三节课。他们做的事情非常简单。一个对减法进行加法,最后一个将实例化两者并简单地打印结果加法和减法。

现在,当我创建 makefile 时,我编译了 Plus.java 和 Minus.java,但不知道如何编译主类,因为它依赖于前两个类。如果可能的话,我想从 makefile 编译并运行它。

当我尝试运行 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

我不知道如何继续;如果我的问题太简单,请原谅我,但我是这些东西的新手。我搜索了很多网站但没有答案。

这是我的 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

I have a problem with a 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. I want to compile and run it from the makefile if it's possible.

I get the above results when I try to run 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:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

半世晨晓 2024-09-08 06:25:09

您需要将源文件的名称传递给 javac:

javac -g Plus.java

更好的选择可能是:

javac -g *.java

Java 世界中很少有人直接调用 javac 或使用 makefile。大多数人在开发时使用 IDE:

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

然后是用于最终/自动化构建的更全面的构建工具:

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

这两个都可以从 make 调用,或者确实可以调用 make 自身,以便与现有的构建系统集成。

编辑:
看来你的 makefile 有问题。看看这是否有效:

JCC = javac
JCR = java
JFLAGS = -g

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

run:
[TAB]$(JCR) Operation

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

将 [TAB] 替换为实际的制表符 - 正如您可能知道这在 make 中非常重要!

You need to pass the names of source files to 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. Most people use an IDE when developing:

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

And then a more comprehensive build tool for final / automated builds:

Ant: http://ant.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.

EDIT:
It seems you have a makefile issue. 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!

神也荒唐 2024-09-08 06:25:09

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

you need to run javac -g Plus.java Minus.java (not .class)

哎呦我呸! 2024-09-08 06:25:09

试试这个。唉,使用 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

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.

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
可爱暴击 2024-09-08 06:25:09

我解决了。这是包裹的问题。我在 netbeans 中编辑了我的文件并保留了:

进行打包操作

对每个文件

,这样我就可以编译操作,但现在它没有运行

愚蠢的问题....

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

I solved it. It was a problem with the packages. I edited my files in netbeans and remained:

package operations

to every one of them

so I got Operation to compile but now it didn't run

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文