我写了一个简单的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="buildclasses"/>
<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 文件都是使用循环的最后一个配置创建的。
谢谢你的帮助。
我能建议一种避免 python 程序启动 ANT 的替代方法吗?
例
├── build.xml
├── moduleA
│ ├── build.properties
│ └── build.xml
└── moduleB
├── build.properties
└── build.xml
构建.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>
模块 A/构建.xml
每个生成文件导入该子项目的本地属性
<project name="module" default="build">
<property file="build.properties"/>
..
..
</project>