如何从命令行上的属性文件加载Ant属性?

Mut*_*mar 11 ant properties build

我有两个属性文件[ one.propertiestwo.properties].我想从命令行动态地将属性文件加载到我的Ant项目中.

我的构建文件名是build.xml.

命令行:

> ant build [How do I pass the property file names here?]
Run Code Online (Sandbox Code Playgroud)

Chr*_*ert 21

从命令行加载属性文件

ant -propertyfile one.properties -propertyfile two.properties 
Run Code Online (Sandbox Code Playgroud)

可以在命令行上使用-D标志定义各个属性:

ant -Dmy.property=42
Run Code Online (Sandbox Code Playgroud)


从Ant项目中加载属性文件

LoadProperties Ant任务

<loadproperties srcfile="one.properties" />
<loadproperties srcfile="two.properties" />
Run Code Online (Sandbox Code Playgroud)

属性Ant任务

<property file="one.properties" />
<property file="two.properties" />
Run Code Online (Sandbox Code Playgroud)

使用模式匹配属性文件

JB Nizet的解决方案结合了concatfileset:

<target name="init" description="Initialize the project.">
  <mkdir dir="temp" />
  <concat destfile="temp/combined.properties" fixlastline="true">
    <fileset dir="." includes="*.properties" />
  </concat>
  <property file="temp/combined.properties" />
</target>
Run Code Online (Sandbox Code Playgroud)