java 的 Makefile
我正在 Windows 中运行 Eclipse 来做我的作业。我必须提交一个 makefile 以便可以编译我的代码(singlefile.java)。我该怎么办呢。
我找到了这个。可以在windows上测试吗?
编辑: 根据建议,我为 Windows 安装了 gnu make:
我的 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
但是,当我运行 make 时,我收到错误:
*** missing separator (did you mean TAB instead of 8 spaces?). Stop.
I am new to make
。我缺少什么?
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.
I found this. Can it be tested on windows.
EDIT:
As per the suggestions, I installed gnu make for windows:
My make file is as follows:
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:
*** missing separator (did you mean TAB instead of 8 spaces?). Stop.
I am new to make
. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
使用此 makefile 所需要做的就是将
Purchaser.java
更改为.java
源,并从中删除其他 .java 源。如果您使用 Windows,那么您的系统中可能没有安装make
。您可以安装和使用 GNU make、Microsoft nmake 或其他。我认为编译程序的最简单方法是制作.bat
文件,其内容如下:当然,您可以添加 javac 标志,例如
-deprecation
等。最简单的形式 < code>makefile 在您的情况下可能看起来像:
确保使用制表符进行缩进(在
javac
和del
等命令之前)。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 havemake
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:Of course you can add there javac flags like
-deprecation
etc.Simplest form of
makefile
in your case can look like:Be sure to make indentation (before commands like
javac
anddel
) with tab character.如果您没有任何依赖项,则可以像编写 C 程序一样编写 makefile,其中包含以下内容:(
注意:您可能还需要一个干净的任务)
如果您打算继续使用 java 来了解更多信息然而,高级项目请考虑使用 Maven 或 ant 来构建您的项目。两者都可以集成到 eclipse 中,因此您无需做太多工作。然后,您可以将“mvncompile”命令包装到 Makefile 中,然后就不用管它了。
If you don't have any dependencies, you can write a makefile just as you would with C programs with something like:
(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.
Make 坚持使用制表符而不是空格。错误消息甚至告诉您“(您的意思是 TAB 而不是 8 个空格吗?)”。因此,转到代码缩进的行,按退格键 8 次,然后按 Tab 键。在所有线路上都这样做,它就会起作用。
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.
因为您使用的是 Eclipse 和 Java,所以您应该查看 创建 Ant 构建文件。
Because you're using Eclipse and Java you should look at creating an Ant buildfile.
你必须使用make吗?或者你可以使用任何构建工具。 Make 很少用于 java,通常是 ant.apache.org 或 maven.apache.org,第一个更简单。
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.
您链接的 Makefile 是一个合适的起点。
仅当您安装了 Cygwin 或类似的东西时。即便如此,您创建包含 Windows 平台依赖项的 makefile 的风险也很小……
我建议您在他们为您提供的用于进行软件开发的平台上测试 makefile,这很可能是某种风格UNIX ...鉴于他们希望您提供 makefile。
但正如其他人所说,如果可以选择,请使用 Ant 而不是 Make 来构建简单的 Java 项目。 Ant 的优点是更加独立于平台,并且除了 Ant 安装和 Java 安装之外几乎不需要什么。
The Makefile you linked is a suitable starting point.
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 ...
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.
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.
从 http://www.wanderinghorse.net/computing/make/< 下载“使用 GNU make 管理项目” /a> 由 Stephan Beal 编写,原始版本由 Robert Mecklenburg 编写,请参阅第 121 页。它拥有使用 gnumake 构建 Java 所需的一切
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