javac的Makefile编译问题
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要将源文件的名称传递给 javac:
更好的选择可能是:
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 有问题。看看这是否有效:
将 [TAB] 替换为实际的制表符 - 正如您可能知道这在 make 中非常重要!
You need to pass the names of source files to javac:
A better option is possibly:
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:
Replace [TAB] with an actual tab character - as you probably know this is incredibly important in make!
你需要运行 javac -g Plus.java Minus.java (不是 .class)
you need to run javac -g Plus.java Minus.java (not .class)
试试这个。唉,使用 make 管理 Java 类依赖关系是一件很痛苦的事情(在相对较大的项目中也曾这样做过),所以您仍然应该认真考虑使用 Ant 或其他一些合适的工具。
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.
我解决了。这是包裹的问题。我在 netbeans 中编辑了我的文件并保留了:
进行打包操作
对每个文件
,这样我就可以编译操作,但现在它没有运行
愚蠢的问题....
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....