用蚂蚁创建一个捆绑罐

我正在使用Ant构建一些Java项目。

在某些情况下,我有一个lib/目录,该目录包含JAR文件形式的外部依赖项。


在构建期间,我通过将目录中zipfileset每个jar的a添加到bundle jar文件中,来创建一个捆绑jar,其中包含项目代码以及相关性lib/。


问题是,每次添加一个jar或更改名称时,我都需要记住要更新build.xml文件,因为我找不到zipfilesets自动添加方式的方法,该方式将以特定模式包含所有jar(例如lib/*.jar)。


有更好的方法吗?


我已经考虑过为此编写自己的Ant任务,或者使用Groovy的ant API以编程方式进行此操作,但是我想知道是否存在使用“香草”蚂蚁进行此操作的方法。


www说
浏览 335回答 3
3回答

红糖糍粑

在我的目标中,我有这样的东西:<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">&nbsp; &nbsp; <zipgroupfileset dir="dist" includes="*.jar"/>&nbsp; &nbsp; <zipgroupfileset dir="dist/lib" includes="*.jar" excludes=""/>&nbsp; &nbsp; <manifest>&nbsp; &nbsp; &nbsp; &nbsp; <attribute name="Main-Class" value="${main.class}"/>&nbsp; &nbsp; &nbsp; &nbsp; <attribute name="Class-Path" value="${mf.classpath}"/>&nbsp; &nbsp; </manifest></jar>这是我如何构建我的类路径:<path id="build.classpath">&nbsp; &nbsp; <fileset dir="${basedir}/">&nbsp; &nbsp; &nbsp; &nbsp; <include name="${lib.dir}/*.jar"/>&nbsp; &nbsp; </fileset></path><pathconvert property="mf.classpath" pathsep=" ">&nbsp; &nbsp; <path refid="build.classpath"/>&nbsp; &nbsp; <mapper>&nbsp; &nbsp; &nbsp; &nbsp; <chainedmapper>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <flattenmapper/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <globmapper from="*.jar" to="lib/*.jar"/>&nbsp; &nbsp; &nbsp; &nbsp; </chainedmapper>&nbsp; &nbsp; </mapper></pathconvert>从上面发布的包目标中使用mf.classpath。这部分是我从其他地方复制的,所以我并不那么熟悉。快速编辑。Javac也需要了解这些jar。<path id="jars">&nbsp; &nbsp; <fileset dir="${lib.dir}" includes="**/*.jar"/></path><target name="compile">&nbsp; &nbsp; <mkdir dir="${build.dir}"/>&nbsp; &nbsp; <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="jars" debug="on"/></target>

MM们

使用zipgroupfileset。例如:<target name="jar">&nbsp; &nbsp; <jar destfile="foo.jar" basedir="${dir.classes}">&nbsp; &nbsp; &nbsp; &nbsp; <zipgroupfileset dir="lib" includes="*.jar"/>&nbsp; &nbsp; </jar></target>

湖上湖

对于那些使用NetBeans的用户,这里是如何使用zipgroupfileset捆绑的库创建JAR存档的方法:<target name="-post-jar">&nbsp; &nbsp; <property name="store.jar.name" value="MyJarName"/>&nbsp; &nbsp; <property name="store.dir" value="dist"/>&nbsp; &nbsp; <property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>&nbsp; &nbsp; <echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>&nbsp; &nbsp; <jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">&nbsp; &nbsp; &nbsp; &nbsp; <zipgroupfileset dir="dist" includes="*.jar"/>&nbsp; &nbsp; &nbsp; &nbsp; <zipgroupfileset dir="dist/lib" includes="*.jar"/>&nbsp; &nbsp; &nbsp; &nbsp; <manifest>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <attribute name="Main-Class" value="${main.class}"/>&nbsp; &nbsp; &nbsp; &nbsp; </manifest>&nbsp; &nbsp; </jar>&nbsp; &nbsp; <zip destfile="${store.jar}">&nbsp; &nbsp; &nbsp; &nbsp; <zipfileset src="${store.dir}/temp_final.jar"&nbsp; &nbsp; &nbsp; &nbsp; excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>&nbsp; &nbsp; </zip>&nbsp; &nbsp; <delete file="${store.dir}/temp_final.jar"/>&nbsp; &nbsp; <delete dir="${store.dir}/lib"/>&nbsp; &nbsp; <delete file="${store.dir}/README.TXT"/></target>我已将此目标定义添加到build.xml文件的末尾。目标名称是-post-jar。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java