gpt4 book ai didi

java - 使用 Ant 进行多次 war 构建

转载 作者:太空宇宙 更新时间:2023-11-04 12:49:37 26 4
gpt4 key购买 nike

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

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

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

我不知道我做错了什么。

这是我的 ant 构建(由于商业原因,名称被隐藏)

<?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 文件都会使用循环的最后配置创建。

感谢您的帮助。

最佳答案

我可以建议一种避免 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>

模块A/build.xml

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

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

<property file="build.properties"/>

..
..
</project>

关于java - 使用 Ant 进行多次 war 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35956806/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com