我正在尝试在一个ant任务中创建4个单独的jar文件,但我不确定如何执行此操作。这是我必须在清单中添加的东西吗?我希望能够有一个jar任务,但能够分别运行我的java程序prob1 prob2 prob3和prob4。那可能吗?任何帮助将不胜感激。
这是我现在的jar任务:
<target name="jar">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/prob1.jar" basedir="build/classes" includes="build/classes/*">
<manifest>
<attribute name="Main-Class" value="prob1"/>
</manifest>
</jar>
</target>
答案 0 :(得分:0)
如果您不喜欢复制粘贴,可以为jar
任务创建一个宏:
<macrodef name="create.jar">
<attribute name="name"/>
<sequential>
<jar destfile="build/jar/@{name}.jar" basedir="build/classes"
includes="build/classes/*">
<manifest>
<attribute name="Main-Class" value="@{name}"/>
</manifest>
</jar>
</sequential>
</macrodef>
并像这样使用它:
<target name="jar">
<mkdir dir="build/jar"/>
<create.jar name="prob1"/>
<create.jar name="prob2"/>
<create.jar name="prob3"/>
<create.jar name="prob4"/>
</target>
另一种方法是使用Ant-Contrib库,为您提供for loop:
<target name="jar">
<mkdir dir="build/jar"/>
<for list="1,2,3,4" param="num">
<sequential>
<jar destfile="build/jar/prob@{num}.jar" basedir="build/classes"
includes="build/classes/*">
<manifest>
<attribute name="Main-Class" value="prob@{num}"/>
</manifest>
</jar>
</sequential>
</for>
</target>