java 的 Makefile

发布于 2024-09-29 15:59:09 字数 680 浏览 2 评论 0原文

我正在 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 技术交流群。

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

发布评论

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

评论(7

雄赳赳气昂昂 2024-10-06 15:59:09

使用此 makefile 所需要做的就是将 Purchaser.java 更改为 .java 源,并从中删除其他 .java 源。如果您使用 Windows,那么您的系统中可能没有安装 make。您可以安装和使用 GNU make、Microsoft nmake 或其他。我认为编译程序的最简单方法是制作 .bat 文件,其内容如下:

javac MyClacc.java

当然,您可以添加 javac 标志,例如 -deprecation 等。

最简单的形式 < code>makefile 在您的情况下可能看起来像:

default:
    javac singlefile.java

clean:
    del singlefile.class

确保使用制表符进行缩进(在 javacdel 等命令之前)。

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:

javac MyClacc.java

Of course you can add there javac flags like -deprecation etc.

Simplest form of makefile in your case can look like:

default:
    javac singlefile.java

clean:
    del singlefile.class

Be sure to make indentation (before commands like javac and del) with tab character.

窝囊感情。 2024-10-06 15:59:09

如果您没有任何依赖项,则可以像编写 C 程序一样编写 makefile,其中包含以下内容:(

JAVAC = javac

%.class: %.java
    $(JAVAC) 
lt;

注意:您可能还需要一个干净的任务)

如果您打算继续使用 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:

JAVAC = javac

%.class: %.java
    $(JAVAC) 
lt;

(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.

淡莣 2024-10-06 15:59:09

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.

浪推晚风 2024-10-06 15:59:09

因为您使用的是 Eclipse 和 Java,所以您应该查看 创建 Ant 构建文件

Because you're using Eclipse and Java you should look at creating an Ant buildfile.

八巷 2024-10-06 15:59:09

你必须使用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.

记忆で 2024-10-06 15:59:09

您链接的 Makefile 是一个合适的起点。

可以在windows上测试吗?

仅当您安装了 Cygwin 或类似的东西时。即便如此,您创建包含 Windows 平台依赖项的 makefile 的风险也很小……

我建议您在他们为您提供的用于进行软件开发的平台上测试 makefile,这很可能是某种风格UNIX ...鉴于他们希望您提供 makefile。

但正如其他人所说,如果可以选择,请使用 Ant 而不是 Make 来构建简单的 Java 项目。 Ant 的优点是更加独立于平台,并且除了 Ant 安装和 Java 安装之外几乎不需要什么。

The Makefile you linked is a suitable starting point.

Can it be tested on 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 ...

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.

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