问题
How to put this unix command in ant script?
jar -xvf test.ear out.war | jar -x ; cd directory ; jar -xvf ../out.war
Will this work?
<target name="unear">
<echo>***Un-tarring***</echo>
<exec executable="jar" outputproperty="noOfFiles">
<arg value="-xvf" />
<arg value="test.ear out.war" />
<arg value="|" />
<arg value="jar" />
<arg value="-x" />
<arg value=";" />
<arg value="cd directory" />
<arg value=";" />
<arg value="jar" />
<arg value="-xvf" />
<arg value="../out.war" />
</exec>
</target>
回答1:
wars, ears and jars are simply zip files. you can use the unzip task to crack it open. You'll need to break up the unix command in your example into multiple tasks.
回答2:
Pipes are interpreted by the shell, so make the shell interpret those. Say:
<exec executable="sh">
<arg value="-c"/>
<arg value="jar -xvf test.ear out.war | jar -x ; cd directory ; jar -xvf ../out.war"/>
</exec>
回答3:
May be You can do something like this, just to ensure you are running unix commands on Unix OS & you can run any set of unix commands by wrapping inside a script :
<condition property="is.unix">
<os family="unix"/>
</condition>
<if>
<istrue value="${is.unix}"/>
<then>
<chmod file="${script.locater.path}/your_script.ksh" perm="755"/>
<exec executable="${script.locater.path}/your_script.ksh"
dir="${from.dir.you.want.to.execute}">
</exec>
来源:https://stackoverflow.com/questions/18898323/run-unix-command-in-ant-script-build-xml