Using Ant to build multiple jars

泪湿孤枕 提交于 2019-12-10 17:18:33

问题


I have multiple Java eclipse projects. Each of them has "jardesc" file for building jar. It's nice - double click -> finish and jar file is made. 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)? How to do it?


回答1:


Take a look at subant task in ant. You can create ant-file which would call other files to.

    <subant target="create_jar1">
        <fileset dir="." includes="jar2.xml"/>
    </subant>
    <subant target="create_jar2">
        <fileset dir="." includes="jar1.xml"/>
    </subant>



回答2:


You could use the jar target to make the jars for you:

    <jar destfile='destination.jar' basedir='source\dir\' />

so your build.xml would look a little like this:

    <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.




回答3:


You can use some loops to create ant parameters however there is no way to loop to create multiple jars (even with ant-commons extension), a copy & paste is the only viable solution unless you want to write an ant plugin (which doesn't really take that much 2 hours reading docs + write simple plugin)



来源:https://stackoverflow.com/questions/14608566/using-ant-to-build-multiple-jars

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!