[英]Using Ant to build multiple jars
I have multiple Java eclipse projects. 我有多个Java eclipse项目。 Each of them has "jardesc" file for building jar.
他们每个人都有“jardesc”文件用于构建jar。 It's nice - double click -> finish and jar file is made.
这很好 - 双击 - >完成并制作jar文件。 But when i have to export several jars it's a pain - i have to repeat procedure several times.
但是,当我必须出口几个罐子时,这是一个痛苦 - 我必须重复几次程序。 Please tell me, can i use Ant script to run several "jardesc" files at once (and get several jars according to each jardesc file)?
请告诉我,我可以使用Ant脚本一次运行几个“jardesc”文件(并根据每个jardesc文件获取几个罐子)? How to do it?
怎么做?
You could use the jar target to make the jars for you: 您可以使用jar目标为您制作罐子:
<jar destfile='destination.jar' basedir='source\dir\' />
so your build.xml would look a little like this: 所以你的build.xml看起来有点像这样:
<project default="makejars">
<target name="makejars">
<jar destfile="app1.jar" basedir="app1\src\" />
<jar destfile="app2.jar" basedir="app2\src\" />
<jar destfile="app3.jar" basedir="app3\src\" />
</target>
</project>
then just run ant in the same directory as build.xml, and the jars should be made. 然后在与build.xml相同的目录中运行ant,并且应该创建jar。
Take a look at subant
task in ant. 看看ant中的
subant
任务。 You can create ant-file which would call other files to. 您可以创建将调用其他文件的ant文件。
<subant target="create_jar1">
<fileset dir="." includes="jar2.xml"/>
</subant>
<subant target="create_jar2">
<fileset dir="." includes="jar1.xml"/>
</subant>
您可以使用一些循环来创建ant参数,但是没有办法循环创建多个jar (即使使用ant-commons扩展),复制和粘贴是唯一可行的解决方案, 除非您想编写一个ant插件 (它没有'真的花了2个小时阅读docs +写简单的插件)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.