java Makefile问题

发布于 2025-01-06 11:29:41 字数 1207 浏览 1 评论 0原文

对于家庭作业,我必须为我编写的一系列 .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 技术交流群。

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

发布评论

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

评论(3

只怪假的太真实 2025-01-13 11:29:42

您尚未指定如何在 Makefile 中构建 java 类。基本上类似于下面的内容...

.java.class:
        $(JC) $(JFLAGS) $*.java

请参阅此链接,其中有一个很好的例子。

You have not specified how to build the java classes in your Makefile. Essentially something like below...

.java.class:
        $(JC) $(JFLAGS) $*.java

Refer to this link which has a good example.

沉溺在你眼里的海 2025-01-13 11:29:42

修复您的 all 目标,使其依赖于 .class 文件而不是 .java 文件(这些文件已经存在,因此“无需执行任何操作”)。

all : $(CLASSES:.java=.class)

另外,您还必须添加一条规则来将 .java 文件编译为 .class 文件:

%.class : %.java
    $(JC) $(JFLAGS) 
lt;

如果使用上述规则(所谓的 模式规则), .SUFFXES: 不再需要,你可以完全删除它。

Fix your all target to depend on .class files instead of .java files (that are already exist and thus " Nothing to be done").

all : $(CLASSES:.java=.class)

Also, you have to a add a rule to compile .java files into .class files:

%.class : %.java
    $(JC) $(JFLAGS) 
lt;

In case of using the rule above (so-called pattern rule), .SUFFXES: isn't needed anymore, you can remove it at all.

贱贱哒 2025-01-13 11:29:42

正如上面其他人所概述的,您可以轻松地执行以下操作:

%.class : %.java
  javac flags_go_here

...但是这存在一些问题:

  • 如果类之间存在任何依赖关系(并且将会存在),您必须确保顺序正确。没有像 GCC 提供的任何工具或命令行选项来为您生成依赖关系
  • Java 允许类之间的循环依赖关系。除非将它们编译在一起,否则不可能编译两个相互依赖的类,例如:
    • ${JAVAC} ${FLAGS} class1.java class2.java
  • javac 启动时间较长。对于小型项目,您不会注意到它,但对于任何有足够类的项目,它会快速增加,并且您的构建时间会快速下降。

我想出的最佳解决方案如下(使用 GNU-make 风格语法):

all: my.jar

my.jar : c1.java c2.java ... cN.java
  ${JAVAC} ${JAVAC_FLAGS} ${^}
  ${JAR} cf ${JAR_FLAGS} ${@} -C src ${^:%.java=%.class}

# As a bonus, here's how you could do JNI stuff based on individual class files.
# This is necessary because nothing in the build actually depends directly on
# the .class files; if they don't exist and the .jar does, then you need some
# way to get the .class files without rebuilding the jar.

# It's written this way so it's re-usable.
# I'm using 'unzip' instead of 'jar' because it has the -j option so it won't
# dump some/irritating/path/to/work/with/when/all/I/need/is/the/.class/file
define CANNED_JAVAH_TARGET =
$(if $(filter %.java,${^}),,\
  $(error When building ${@}: No jar dependency provided))
unzip -j -d /somewhere/to/put/temp/class/file \
  $(filter %.jar,${^}) ${PKG_PATH}/${@F:%.h=%.class}
${JAVAH} ${JAVAH_FLAGS} <whatever flags are needed to make the header>
endef

${JNI_HEADER_TARGETS} : my.jar
  ${CANNED_JAVAH_TARGET}

javah 部分存在问题:对于 JAVAH 事物,如果有人让它依赖于多个 jar,那么它'会打破的。上面可能有一些小错误或需要解决的问题(这里凭记忆),但总而言之,它对我来说没有太多麻烦。

As outlined by others above, you can easily do something like this:

%.class : %.java
  javac flags_go_here

... but there's a few problems with this:

  • If there are any dependencies between classes -- and there will be -- you'll have to get the order right. There aren't any tools or command-line options like what GCC provides for generating dependencies for you
  • Java allows circular dependencies between classes. It isn't possible to compile two classes that depend on each-other unless you compile them together, eg:
    • ${JAVAC} ${FLAGS} class1.java class2.java
  • 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):

all: my.jar

my.jar : c1.java c2.java ... cN.java
  ${JAVAC} ${JAVAC_FLAGS} ${^}
  ${JAR} cf ${JAR_FLAGS} ${@} -C src ${^:%.java=%.class}

# As a bonus, here's how you could do JNI stuff based on individual class files.
# This is necessary because nothing in the build actually depends directly on
# the .class files; if they don't exist and the .jar does, then you need some
# way to get the .class files without rebuilding the jar.

# It's written this way so it's re-usable.
# I'm using 'unzip' instead of 'jar' because it has the -j option so it won't
# dump some/irritating/path/to/work/with/when/all/I/need/is/the/.class/file
define CANNED_JAVAH_TARGET =
$(if $(filter %.java,${^}),,\
  $(error When building ${@}: No jar dependency provided))
unzip -j -d /somewhere/to/put/temp/class/file \
  $(filter %.jar,${^}) ${PKG_PATH}/${@F:%.h=%.class}
${JAVAH} ${JAVAH_FLAGS} <whatever flags are needed to make the header>
endef

${JNI_HEADER_TARGETS} : my.jar
  ${CANNED_JAVAH_TARGET}

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.

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