Run UNIX command in ant script - build.xml

2019-08-14 05:52发布

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>

标签: java unix ant
3条回答
Viruses.
2楼-- · 2019-08-14 06:01

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.

查看更多
聊天终结者
3楼-- · 2019-08-14 06:12

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>
查看更多
祖国的老花朵
4楼-- · 2019-08-14 06:15

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>
查看更多
登录 后发表回答