是否可以从 Java 运行 Makefile?

发布于 2024-08-20 21:57:08 字数 85 浏览 5 评论 0原文

我在互联网上搜索,但只找到了生成 Java Makefile 的示例。我的情况有所不同,如果我有一个 Makefile,但我只想从 Java 运行它怎么办?

I was searching the Internet but only got examples of generating a Java Makefile. My case is different, what if I have a Makefile, but I just want to run it from Java?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

以可爱出名 2024-08-27 21:57:08

您并不是真正“运行”makefile,而是运行 make 实用程序,它会在当前目录中查找名为“makefile”或“Makefile”的文件并处理该文件中的命令。因此,您需要在 Java 应用程序中执行 make 。您可以通过 Runtime.exec() 来完成此操作。有关详细信息,请参阅 http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#exec%28java.lang.String%29http://www.javaworld.com/javaworld/ jw-12-2000/jw-1229-traps.html?page=1

您应该注意的一个潜在问题是 make 可能存在于您的程序所在的计算机上,也可能不存在继续运行,即使它确实存在,它也可能位于非标准位置。在我的机器上,它是 /usr/bin/make,但它可能位于其他地方。请小心考虑这一点。

You don't really "run" a makefile, rather, you run the make utility and it looks for a file called "makefile" or "Makefile" in your current directory and processes the commands in that file. So you need to execute make from within your java app. You can do this via Runtime.exec(). For more information see http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#exec%28java.lang.String%29 and http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1

One potential issue you should look out for is that make may or may not exist on the machine that your program runs on, and even if it does exist, it may be located in a non-standard location. On my machine, it's /usr/bin/make, but it could be located elsewhere. Be careful to account for this.

泪冰清 2024-08-27 21:57:08

是的。您可以使用 Runtime.exec 来运行 make 应用程序。但是,正如前面有人所说,您应该考虑文件可能不存在或存在于其他位置的情况。我建议您查看 java.io.File javadoc 它提供了此功能。另外,不要忘记捕获错误流以用于日志记录/调试目的。很多时候,程序员只实现输入和输出流。

Yes. You can use Runtime.exec to run the make application. However, as someone previously stated, you should account for conditions when the file may not be present or present in another location. I suggest you to have a look at java.io.File javadoc which provides this functionality. Also, don't forget to capture the error stream for logging/debugging purposes. Many a times, programmers only implement the input and output streams.

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