使用ant

时间:2016-03-12 11:01:31

标签: java web-applications ant build war

我写了一个简单的python脚本,它改变了java项目中的一些配置。然后,脚本调用ant脚本来构建.war文件并将其移动到另一个文件夹中。

我必须使用不同的配置构建几个.war文件。 一切正常,如果我手动运行脚本,那么一个配置。

如果我循环配置,相反,我创建和复制的所有战争文件都具有与上次战争创建相同的配置!

我无法弄清楚我做错了什么。

这里是我的蚂蚁构建(由于商业原因,名称被掩盖)

<?xml version="1.0" encoding="UTF-8"?>
<project name="Deploy From Eclipse to JBoss" basedir="." default="deploy">
  <!-- This replace with yours project name and JBoss location: -->
  <property name="warfile" value="xxx"/>
  <property name="deploy" value="C:\\Users\\xxx\\Documents\\tmp"/>
  <target name="create">
      <war destfile="${warfile}.war" webxml="WebContent/WEB-INF/web.xml" update="true">
        <classes dir="build\classes"/>
        <fileset dir="WebContent">
            <exclude name="WEB-INF/web.xml"/>
        </fileset>
      </war>
  </target>
  <target name="copy">
      <copy todir="${deploy}" overwrite="true">
        <fileset dir=".">
          <include name="${warfile}.war"/>
        </fileset>
      </copy>
  </target>
  <target name="clear">
      <delete includeemptydirs="true">
        <fileset dir="${deploy}" defaultexcludes="false">
          <include name="${warfile}.*/**" />
        </fileset>
      </delete>
  </target>
  <target name="deploy">
      <antcall target="create"/>
      <antcall target="clear"/>
      <antcall target="copy"/>
  </target>
</project>

这里有一段pyhon代码

'''setup the base info for the changes in the settings'''
for c in c_dict:
  '''...apply the changes to the required files...'''
  final_output_path = outputpath+country+"\\xxx.war"
  os.system("ant -f ../build.xml")
  copyfile(starting_location, final_output_path)
  os.remove(starting_location) 

更清楚一点:如果我在没有循环的情况下调用脚本,那么如果我通过指定它来为每个配置运行它,那么一切正常。

如果我放置循环,则使用循环的最后一个配置创建所有war文件。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我可以建议一种避免python程序启动ANT的替代方法吗?

实施例

├── build.xml
├── moduleA
│   ├── build.properties
│   └── build.xml
└── moduleB
    ├── build.properties
    └── build.xml

的build.xml

<project name="parent" default="build">

  <target name="build">
    <subant>
      <filelist dir=".">
        <file name="moduleA/build.xml"/>
        <file name="moduleB/build.xml"/>
      </filelist>
      <target name="clean"/>
      <target name="build"/>
    </subant>
  </target>

</project>

moduleA / build.xml中

每个构建文件都会导入该子项目的本地属性

<project name="module" default="build">

  <property file="build.properties"/>

  ..
  ..
</project>