Run UNIX command in ant script - build.xml

徘徊边缘 提交于 2019-12-24 12:14:20

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!