java Makefile问题
对于家庭作业,我必须为我编写的一系列 .java 文件制作 makefile(物理上和软件上)。
我已经编写了一个 make 文件:
JFLAGS = -d -g bin/
JC = javac
.SUFFXES: .java .class
CLASSES = \
cdn\communications\CommandReader.java \
cdn\communications\CommandReaderFactory.java \
cdn\communications\CommandReaderThread.java \
cdn\communications\DiscoveryCommandReader.java \
cdn\communications\Link.java \
cdn\communications\RefreshThread.java \
cdn\communications\RouterCommandReader.java \
cdn\node\Discovery.java \
cdn\node\Node.java \
cdn\node\Router.java \
cdn\utility\Utility.java \
cdn\wireformats\DeRegisterRequest.java \
cdn\wireformats\DeRegisterResponse.java \
cdn\wireformats\LinkInfo.java \
cdn\wireformats\LinkWeightUpdate.java \
cdn\wireformats\MessageType.java \
cdn\wireformats\PeerRouterList.java \
cdn\wireformats\RegisterRequest.java \
cdn\wireformats\RegisterResponse.java \
cdn\wireformats\RouterInfo.java \
cdn\wireformats\WireFormatFactory.java \
all : $(CLASSES)
clean : $(CLASSES:.java=.class)
但是当我运行它时,我收到消息“make:没有为‘all’做任何事情。”我的文件都没有制作。
我在这里缺少什么吗?我正在从包含“cdn”目录层次结构的目录运行该文件吗?
任何想法将不胜感激。
For a homework assignment I have to make a makefile (physically and in software) for a series of .java files that I have written.
I have written up a make file:
JFLAGS = -d -g bin/
JC = javac
.SUFFXES: .java .class
CLASSES = \
cdn\communications\CommandReader.java \
cdn\communications\CommandReaderFactory.java \
cdn\communications\CommandReaderThread.java \
cdn\communications\DiscoveryCommandReader.java \
cdn\communications\Link.java \
cdn\communications\RefreshThread.java \
cdn\communications\RouterCommandReader.java \
cdn\node\Discovery.java \
cdn\node\Node.java \
cdn\node\Router.java \
cdn\utility\Utility.java \
cdn\wireformats\DeRegisterRequest.java \
cdn\wireformats\DeRegisterResponse.java \
cdn\wireformats\LinkInfo.java \
cdn\wireformats\LinkWeightUpdate.java \
cdn\wireformats\MessageType.java \
cdn\wireformats\PeerRouterList.java \
cdn\wireformats\RegisterRequest.java \
cdn\wireformats\RegisterResponse.java \
cdn\wireformats\RouterInfo.java \
cdn\wireformats\WireFormatFactory.java \
all : $(CLASSES)
clean : $(CLASSES:.java=.class)
But when I run it I get the message "make: Nothing to be done for `all'." and none of my files are made.
Is there something I'm missing here? I'm running the file from the directory that holds the "cdn" directory hierarchy?
Any thoughts would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您尚未指定如何在 Makefile 中构建 java 类。基本上类似于下面的内容...
请参阅此链接,其中有一个很好的例子。
You have not specified how to build the java classes in your Makefile. Essentially something like below...
Refer to this link which has a good example.
修复您的
all
目标,使其依赖于 .class 文件而不是 .java 文件(这些文件已经存在,因此“无需执行任何操作”)。另外,您还必须添加一条规则来将 .java 文件编译为 .class 文件:
如果使用上述规则(所谓的 模式规则),
.SUFFXES:
不再需要,你可以完全删除它。Fix your
all
target to depend on .class files instead of .java files (that are already exist and thus " Nothing to be done").Also, you have to a add a rule to compile .java files into .class files:
In case of using the rule above (so-called pattern rule),
.SUFFXES:
isn't needed anymore, you can remove it at all.正如上面其他人所概述的,您可以轻松地执行以下操作:
...但是这存在一些问题:
javac
启动时间较长。对于小型项目,您不会注意到它,但对于任何有足够类的项目,它会快速增加,并且您的构建时间会快速下降。我想出的最佳解决方案如下(使用 GNU-make 风格语法):
javah 部分存在问题:对于 JAVAH 事物,如果有人让它依赖于多个 jar,那么它'会打破的。上面可能有一些小错误或需要解决的问题(这里凭记忆),但总而言之,它对我来说没有太多麻烦。
As outlined by others above, you can easily do something like this:
... but there's a few problems with this:
javac
has a long start-up time. For small projects you won't notice it, but for any project where there's enough classes it'll add up fast, and your build times go downhill fast.The best solution I've come up with is something like the following (using GNU-make style syntax):
There is a problem with the javah portion: for the JAVAH thing, if someone makes it depend on more than one jar, it'll break. There may be a few minor mistakes or things to work around in the above (going from memory here), but all in all it has worked for me without much hassle.