如何将 build.xml 中定义的变量值传递给 Java 类

发布于 2025-01-05 04:20:44 字数 44 浏览 1 评论 0原文

请提供一种将 build.xml 中定义的变量值传递给 Java 类的方法

Please provide a way to pass variable value defined in build.xml to Java class

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

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

发布评论

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

评论(2

葮薆情 2025-01-12 04:20:44

您的构建过程是一回事,您的应用程序运行是另一回事。您无法在运行时将构建参数传递给类。

也许解决您的问题的方法是将 build.xml 中找到的参数写入 manifest.mf,然后在运行时从那里读取它。

你可以这样做:

build.xml
<manifest file="MANIFEST.MF">
    <attribute name="MyParameter" value="123"/>
</manifest>

在你的java文件中,看看答案阅读我自己的Jar 的清单

Your build process is one thing, your app running is another. You can't pass a build parameter to a class at runtime.

Perhaps a solution to your problem would be to write your parameter found in build.xml to manifest.mf, and then read it from there at runtime.

You can do it like this:

build.xml
<manifest file="MANIFEST.MF">
    <attribute name="MyParameter" value="123"/>
</manifest>

And in your java file, take a look at the answer Reading my own Jar's Manifest.

横笛休吹塞上声 2025-01-12 04:20:44

您必须使用 XML 解析器才能做到这一点。阅读此内容以获取更多信息 http://www.java-samples.com/showtutorial。 php?tutorialid=152

You will have to use an XML parser to do that. Read this for more info http://www.java-samples.com/showtutorial.php?tutorialid=152

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