【问题标题】:Multiple war build with ant与蚂蚁的多重战争构建
【发布时间】:2016-03-12 11:01:31
【问题描述】:

我写了一个简单的 python 脚本,它改变了一个 java 项目中的一些配置。然后,该脚本调用一个 ant 脚本来构建 .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代码的sn-p

'''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文件都是用循环的最后一个配置创建的。

感谢您的帮助。

【问题讨论】:

    标签: java web-applications ant build war


    【解决方案1】:

    我能否建议一种避免 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多