创建具有一个蚂蚁的jar包 [英] Creating a bundle jar with ant
问题描述
我使用Ant来构建一些Java项目。结果
在有些国家,我有一个的lib /
目录,其中包含外部依赖,在表格上的JAR文件。
I'm using Ant to build some Java projects.
In some, I've got a lib/
directory, which contains external dependencies, in the form on JAR files.
在构建,我创建了一个捆绑的罐子,包含项目的code,依赖一起,加入到包JAR文件中的 zipfileset
每个在坛子里的的lib /
目录
During the build, I create a bundled jar, that contains the project's code, alongside the dependencies, by adding to the bundle jar file a zipfileset
for each of the jars in the lib/
directory.
问题是,每次我加一个罐子,或时间更改名称,我需要记住更新的build.xml
文件,因为我找不到添加以自动方式的 zipfilesets
,其中将包括在一定的模式的所有jar文件的方式(如的lib / *。JAR
)。
The problem is, that every time I add a jar, or change names, I need to remember to update the build.xml
file, as I couldn't find a way for adding those zipfilesets
in an automatic manner that will include all jars in a certain pattern (e.g. lib/*.jar
).
是否有这样做的更好的办法?
Is there a better way for doing this?
我考虑过写我自己的Ant任务对于这一点,或使用Groovy的蚂蚁API以编程方式做到这一点,但不知道是否有这样做的用普通蚁的方法。
I've considered writing my own Ant Task for this, or using Groovy's ant API to do this programmatically, but was wondering if there's a way for doing this using "vanilla" ant.
谢谢!
推荐答案
在我的目标,我有这样的事情:
In my target, I have something like this:
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar" excludes=""/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
<attribute name="Class-Path" value="${mf.classpath}"/>
</manifest>
</jar>
和这里是如何我建立我的类路径:
And here is how I build my classpath:
<path id="build.classpath">
<fileset dir="${basedir}/">
<include name="${lib.dir}/*.jar"/>
</fileset>
</path>
<pathconvert property="mf.classpath" pathsep=" ">
<path refid="build.classpath"/>
<mapper>
<chainedmapper>
<flattenmapper/>
<globmapper from="*.jar" to="lib/*.jar"/>
</chainedmapper>
</mapper>
</pathconvert>
mf.classpath从上面张贴的包目标使用。
这部分我从别的地方抄,所以我不是那么熟悉。
mf.classpath is used from the package target posted above. This part I copied from somewhere else, so I'm not all that familiar with it.
快速编辑。
javac的需要了解这些罐子了。
Quick edit. Javac needs to know about those jars too.
<path id="jars">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>
<target name="compile">
<mkdir dir="${build.dir}"/>
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="jars" debug="on"/>
</target>
这篇关于创建具有一个蚂蚁的jar包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!