简体   繁体   English

用蚂蚁打造多个战争

[英]Multiple war build with ant

I wrote a simple python script which changes some configurations in a java project. 我编写了一个简单的python脚本,该脚本更改了Java项目中的某些配置。 Then, the script invokes an ant script to build the .war file and move it into a different folder. 然后,该脚本调用一个ant脚本来构建.war文件并将其移动到另一个文件夹中。

I have to build several .war file with different configurations. 我必须构建具有不同配置的几个.war文件。 Everything works fine, if i run the script manually, one config at the time. 一切正常,如果我手动运行脚本,则一次配置。

If i loop over the configurations, instead, all the war files i create and copy have the same config of the last war created! 相反,如果我遍历配置,则我创建和复制的所有war文件都具有与上一次创建的war相同的配置!

I can't figure out what i'm doing wrong. 我无法弄清楚我做错了什么。

Here my ant build (names are obscured for business reasons) 在这里我的蚂蚁构建(名称因商业原因而模糊)

<?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>

And here there is a snippet of the pyhon code 这里有一段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) 

To be more clear: if i call the script without the loop, so if I run it for each configuration by specifying it, everything works. 更清楚地说:如果我不带循环调用脚本,那么如果我通过指定它为每种配置运行它,则一切正常。

If i put the loop, all the war file are created with the last configuration of the loop. 如果我放置循环,则使用循环的最后一个配置创建所有war文件。

Thank you for your help. 谢谢您的帮助。

Could I suggest an alternative approach that avoids python programs to launch ANT? 我可以建议一种避免python程序启动ANT的替代方法吗?

Example

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

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 moduleA / build.xml文件

Each build file imports a local properties for that sub-project 每个构建文件都会为该子项目导入一个本地属性

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

  <property file="build.properties"/>

  ..
  ..
</project>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM