推荐使用 :(来自官方文档)
使用 restrict archives
<jar
destfile=
"${lib.dir}/${project.name}-${version}.jar"
basedir=
"${classes.dir}"
>
<restrict>
<name
name=
"**/*.class"
/>
<archives>
<zips>
<fileset
refid=
"log4j-1.2.15.jar"
/>
<fileset
refid=
"commons-codec-1.4.jar"
/>
<fileset
dir=
"${basedir}/lib"
includes=
"*.jar"
/>
<fileset
dir=
"${env.YOYO_SVN_HOME}"
includes=
"app/java/testng/6.8/testng-6.8.jar"
/>
</zips>
</archives>
</restrict>
<manifest>
<attribute
name=
"Main-Class"
value=
"com.yoyosys.woyun.CompareFileMd5OrLength"
/>
</manifest>
</jar>
<jar destfile="${lib.dir}/${project.name}-${version}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Class-Path" value="${mf.classpath}" />
<attribute name="Main-Class" value="com.yoyosys.woyun.CompareFileMd5OrLength"/>
</manifest>
</jar>
这里可以添加 制定的jar 包,但是,制定的jar包 不会在 classpath中使用,所哟要使用
manifest 的 Class-Path 属性 ,将 jar包的内 打进的jar包 ,路径指定了 ,
<attribute name="Class-Path" value="${mf.classpath}" />
<attribute name="Main-Class" value="com.yoyosys.woyun.CompareFileMd5OrLength"/>
</manifest>
</jar>
1 Manifest-Version: 1.0
2 Ant-Version: Apache Ant 1.8.2
3 Created-By: 1.6.0_31-b04 (Sun Microsystems Inc.)
4 Main-Class: com.yoyosys.woyun.CompareFileMd5OrLength
5 Class-Path: log4j-1.2.15.jar commons-codec-1.4.jar
2 Ant-Version: Apache Ant 1.8.2
3 Created-By: 1.6.0_31-b04 (Sun Microsystems Inc.)
4 Main-Class: com.yoyosys.woyun.CompareFileMd5OrLength
5 Class-Path: log4j-1.2.15.jar commons-codec-1.4.jar
将打好的jar包 解压 可以看到 在 :META-INF/MANIFEST.MF 信息中可以看到 表明 在 打好的jar保重 包含 了
log4j-1.2.15.jar commons-codec-1.4.jar 这两个jar 包