我一直在使用宏定义将一组文件复制到不同的位置和FTP服务器。但是复制似乎很慢,所以我想使用7z压缩捆绑包并将所有内容作为单个文件复制到FTP中。可以用7z完成吗?我的amcrodef在其下面工作:
<macrodef name="copyimages">
<attribute name="todir"/>
<sequential>
<copy todir="@{todir}" overwrite="true" failonerror="false">
<fileset dir="${build.output.dir}">
<include name="logs/*${build.id}*armv5*scan2.html"/>
<include name="logs/*${build.id}*main.ant.log"/>
<include name="logs/*${build.id}*bom.xml"/>
<include name="logs/compile/*${build.id}*.*"/>
<include name="logs/cone/*${build.id}*.*"/>
<include name="logs/post/*${build.id}*.*"/>
<include name="logs/roms/*${build.id}*.*"/>
<include name="**/*${build.id}_codescanner/**"/>
</fileset>
</copy>
</sequential>
</macrodef>
<copyimages todir="${publish.ssdoci.dir}/${env.version}.${build.number}"/>
答案 0 :(得分:1)
如果您不是特别关注7z
,那么您可以使用Zip Task。
你可以尝试这样的事情而不是<copy></copy
......
<zip destfile ="@{destfile}">
<fileset dir="${build.output.dir}">
<include name="logs/*${build.id}*armv5*scan2.html"/>
<include name="logs/*${build.id}*main.ant.log"/>
<include name="logs/*${build.id}*bom.xml"/>
<include name="logs/compile/*${build.id}*.*"/>
<include name="logs/cone/*${build.id}*.*"/>
<include name="logs/post/*${build.id}*.*"/>
<include name="logs/roms/*${build.id}*.*"/>
<include name="**/*${build.id}_codescanner/**"/>
</fileset>
</zip>
<copyimages destfile="${publish.ssdoci.file}-${env.version}.${build.number}"/>
答案 1 :(得分:1)
7zip没有任务 - &lt; zip&gt;无法使用密码存档。 因此我的解决方案是
<target name="zip" depends="dist">
<exec executable="C:\Program Files\7-Zip\7z.exe">
<arg value="a" /> <!--archive-->
<arg value="-pMyPasswordt" /> <!-- password -->
<arg value="-r" /> <!-- recursiv -->
<arg value="C:\temp\2012-06-29\${programName}.zip" /> <!-- destination -->
<arg value="${jarFile}" /> <!-- files to archive -->
</exec>
</target>
答案 2 :(得分:0)
我猜使用带有“exec”的7z.exe是最好的选择。
以下是语法:
C:\ Program Files \ 7-Zip&gt; 7z.exe a -t7z c:\ temp \ test.7z c:\ temp * .txt
*此命令将来自c:\ temp的所有.txt文件存档为“test.7z”
干杯!
答案 3 :(得分:0)
这里有一个7z ant任务:http://www.pharmasoft.be/7z/
虽然没有测试,但该网站似乎已经过时了。
答案 4 :(得分:0)
根据apache.org,支持7z
从osdir.com开始,有关于实施sevenz
任务的评论与使用zip的方式相同
使用maven?
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-compress</artifactId>
<version>1.4</version>
</dependency>
蚂蚁
<taskdef resource="org/apache/ant/compress/antlib.xml" classpathref="maven.plugin.classpath"/>
<sevenz destfile ="my.7z">
<fileset dir="${build.output.dir}">
<include name="logs/*${build.id}*armv5*scan2.html"/>
<include name="logs/*${build.id}*main.ant.log"/>
<include name="logs/*${build.id}*bom.xml"/>
<include name="logs/compile/*${build.id}*.*"/>
<include name="logs/cone/*${build.id}*.*"/>
<include name="logs/post/*${build.id}*.*"/>
<include name="logs/roms/*${build.id}*.*"/>
<include name="**/*${build.id}_codescanner/**"/>
</fileset>
</sevenz>
<un7z src="my.7z" dest="unpack" />