Java 生成文件运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16287020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java makefile run
提问by user1058712
I have a project that I created with eclipse. Now I want to copy this project to my linux computer to compile and run it there.
我有一个用 eclipse 创建的项目。现在我想把这个项目复制到我的 linux 电脑上,在那里编译和运行它。
For this I want to create a makefile for compiling and running automatically.
为此,我想创建一个用于自动编译和运行的 makefile。
I already have created a makefile and it can compile my project. But now it should start my program after compiling and I dont know how to make this.
我已经创建了一个 makefile,它可以编译我的项目。但是现在它应该在编译后启动我的程序,我不知道如何制作它。
I want to type "make" and it should compile the source and after that it should start my main automatically. For now I have a shellscript that does the following.
我想输入“make”,它应该编译源代码,然后它应该自动启动我的主程序。现在我有一个执行以下操作的 shellscript。
make
java Main
I already tried to run "make run" but I get an error.
我已经尝试运行“make run”,但出现错误。
No rule to make target 'Main', needed by 'run'.
This is my Makefile.
这是我的 Makefile。
JFLAGS = -g
JC = javac
JVM= java
FILE=
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSES = \
Main.java \
Class1.java \
Class2.java \
Class3.java \
Class4.java
MAIN = Main
default: classes
classes: $(CLASSES:.java=.class)
run: $(MAIN).class
$(JVM) $(MAIN)
clean:
$(RM) *.class
回答by ValarDohaeris
You need to add classes
rather than Main.class
as a dependency for run, since you haven't defined a rule for Main.class
, i.e. this should work:
您需要添加classes
而不是Main.class
作为运行的依赖项,因为您还没有为 定义规则Main.class
,即这应该有效:
run: classes
$(JVM) $(MAIN)