eclipse 用于 Java 的 Makefile
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4040064/
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
Makefile for java
提问by devnull
I am running Eclipse in windows for doing my homeworks. I have to submit a makefile so that my code (singlefile.java) can be compiled. How can I do this.
我在 Windows 中运行 Eclipse 来做作业。我必须提交一个 makefile 以便我的代码 (singlefile.java) 可以被编译。我怎样才能做到这一点。
I found this. Can it be tested on windows.
我找到了这个。可以在windows上测试吗?
EDIT: As per the suggestions, I installed gnu make for windows:
编辑:根据建议,我为 Windows 安装了 gnu make:
My make file is as follows:
我的make文件如下:
JFLAGS = -g
JC = javac
#
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSES = \
singlefile.java \
default: classes
classes: $(CLASSES:.java=.class)
clean:
$(RM) *.class
However, when I run make, I am getting the error:
但是,当我运行 make 时,出现错误:
*** missing separator (did you mean TAB instead of 8 spaces?). Stop.
I am new to make
. What am I missing?
我是新手make
。我错过了什么?
回答by Ben Taitelbaum
If you don't have any dependencies, you can write a makefile just as you would with C programs with something like:
如果您没有任何依赖项,您可以像使用 C 程序一样编写一个 makefile,例如:
JAVAC = javac
%.class: %.java
$(JAVAC) $<
(note: you'd probably want a clean task as well)
(注意:您可能还需要一个干净的任务)
If you're planning on continuing with java for more advanced projects, however, consider using maven or ant for building your project. Both can be integrated into eclipse so you don't have to do much work. Then you can wrap your 'mvn compile' command into a Makefile and forget about it.
但是,如果您打算继续使用 java 进行更高级的项目,请考虑使用 maven 或 ant 来构建您的项目。两者都可以集成到 eclipse 中,因此您不必做太多工作。然后你可以将你的 'mvn compile' 命令包装到一个 Makefile 中并忘记它。
回答by Micha? Niklas
All you have to do with this makefile is to change Purchaser.java
into your .java
source and remove other .java sources from it. If you use Windows, then you probably do not have make
installed in your system. You can install and use GNU make, Microsoft nmake or other. I think the simplest way to compile your program is to make .bat
file with content like:
您对这个 makefile 要做的就是更改Purchaser.java
为您的.java
源代码并从中删除其他 .java 源代码。如果您使用的是 Windows,那么您的系统中可能还没有make
安装。您可以安装和使用 GNU make、Microsoft nmake 或其他。我认为编译程序的最简单方法是制作.bat
包含以下内容的文件:
javac MyClacc.java
Of course you can add there javac flags like -deprecation
etc.
当然,您可以在那里添加 javac 标志等-deprecation
。
Simplest form of makefile
in your case can look like:
makefile
在您的情况下,最简单的形式可能如下所示:
default:
javac singlefile.java
clean:
del singlefile.class
Be sure to make indentation (before commands like javac
and del
) with tab character.
确保使用制表符进行缩进(在javac
和命令之前del
)。
回答by rflood89
Make insists that you use tabs instead of spaces. The error message even tells you that "(did you mean TAB instead of 8 spaces?)". So go to the lines where the code is indented, press backspace 8 times, then press tab. Do this on all lines and it will work.
Make 坚持使用制表符而不是空格。错误消息甚至告诉您“(您的意思是 TAB 而不是 8 个空格?)”。因此,转到代码缩进的行,按退格键 8 次,然后按 Tab。在所有线路上都这样做,它会起作用。
回答by Catchwa
Because you're using Eclipse and Java you should look at creating an Ant buildfile.
因为您使用的是 Eclipse 和 Java,所以您应该考虑创建一个 Ant 构建文件。
回答by Stephen C
The Makefile you linked is a suitable starting point.
您链接的 Makefile 是一个合适的起点。
Can it be tested on windows?
可以在windows上测试吗?
Only if you have installed Cygwin or something like that. Even then, there is a small risk that you will create a makefile that contains Windows platform dependencies ...
仅当您安装了 Cygwin 或类似的东西时。即便如此,您仍存在创建包含 Windows 平台依赖项的 makefile 的小风险......
I'd recommend testing the makefile on the platform that they provide for you to do your software development on, which is most likely some flavour of UNIX ... given that they expect you to supply a makefile.
我建议在他们为您提供软件开发的平台上测试 makefile,这很可能是某种 UNIX 风格……因为他们希望您提供一个 makefile。
But as others have said, if you have the option, use Ant instead of Make for building simple Java projects. Ant has the advantage of being more platform independent, and requiring little apart from an Ant installation and a Java installation.
但正如其他人所说,如果可以选择,请使用 Ant 而不是 Make 来构建简单的 Java 项目。Ant 的优点是更加独立于平台,并且除了安装 Ant 和安装 Java 之外几乎不需要什么。
回答by MeBigFatGuy
do you have to use make? or can you use any build tool. Make is rarely if ever used for java, usually ant.apache.org or maven.apache.org, the first being simpler.
你必须使用make吗?或者您可以使用任何构建工具。Make 很少用于 java,通常是 ant.apache.org 或 maven.apache.org,第一个更简单。
回答by Robert H
download "managing projects with GNU make" from http://www.wanderinghorse.net/computing/make/by Stephan Beal and original edition by Robert Mecklenburg, and look at page 121. It has everything you need to build Java using gnumake
从http://www.wanderinghorse.net/computing/make/下载 Stephan Beal 的“使用 GNU make 管理项目”和 Robert Mecklenburg 的原始版本,并查看第 121 页。它拥有使用 gnumake 构建 Java 所需的一切