3 回答

TA贡献1815条经验 获得超6个赞
在我的目标中,我有这样的东西:
<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>
这是我如何构建我的类路径:
<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。这部分是我从其他地方复制的,所以我并不那么熟悉。
快速编辑。Javac也需要了解这些jar。
<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>

TA贡献1886条经验 获得超2个赞
使用zipgroupfileset。例如:
<target name="jar">
<jar destfile="foo.jar" basedir="${dir.classes}">
<zipgroupfileset dir="lib" includes="*.jar"/>
</jar>
</target>

TA贡献2003条经验 获得超2个赞
对于那些使用NetBeans的用户,这里是如何使用zipgroupfileset捆绑的库创建JAR存档的方法:
<target name="-post-jar">
<property name="store.jar.name" value="MyJarName"/>
<property name="store.dir" value="dist"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset src="${store.dir}/temp_final.jar"
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
<delete dir="${store.dir}/lib"/>
<delete file="${store.dir}/README.TXT"/>
</target>
我已将此目标定义添加到build.xml文件的末尾。目标名称是-post-jar。
添加回答
举报