3

I am wondering if you can run Ant on a buildfile that would be located inside a JAR. The reason why I am interested in this is because I would like to include a "deploy" target in my buildfile that could be called after the jar has been moved to its destination. That "deploy" target would take care of extracting resources and other libraries required to run the program.

So, for instance, I would package up properties, images and external jars inside of my jar when building. The deployment process would then consist of moving the jar to the location it is meant to run in, and call ant <someOption> myjar.jar/build.xml deploy or something like that.

Does that make sense?

4

2 回答 2

1

Ant 的构建文件解析可以使用ProjectHelper进行扩展。默认一个只加载文件(source)。

您可以将其扩展为处理 XML 源,该源可以来自 jar(可能使用 getResourceAsStream(..))

[ 旁注:您可以以编程方式运行 ant。无需提取然后运行命令行 - 请参阅通过 Java 以编程方式运行 ANT ]

于 2013-09-30T05:29:58.337 回答
1

我认为没有办法ant可以在 jar 中获取构建文件。

对于您描述的方法,您需要解压缩build.xml并将其传递给 ant。由于 ant 不stdin作为构建文件的参数,因此您需要存储构建文件然后将其删除:

$ unzip myjar.jar build.xml

$ ant deploy

$ rm build.xml

但是应用程序运行环境是否必须安装ant才能提取这些资源?不能在您的应用程序中完成吗?或者你不能用你的 jar、库 jar 和图像分发一个 zip 文件吗?

或者也许创建一个安装程序应该更合适:I\Pack或者,如果只有 Windows,则NSIS

于 2013-09-27T21:00:20.810 回答