我有两个属性文件[one.properties
和two.properties
]。我想从命令行动态地将属性文件加载到我的Ant项目中。
我的构建文件名是build.xml。
命令行:
> ant build [How do I pass the property file names here?]
答案 0 :(得分:21)
ant -propertyfile one.properties -propertyfile two.properties
可以在命令行上使用-D
标志定义单个属性:
ant -Dmy.property=42
<loadproperties srcfile="one.properties" />
<loadproperties srcfile="two.properties" />
<property file="one.properties" />
<property file="two.properties" />
JB Nizet's解决方案将concat与fileset合并:
<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>
答案 1 :(得分:0)
进行构建condition,以便如果为构建提供了必需的系统参数,则仅允许下一个目标,否则构建失败。
Pass CMD: ant -DclientName=Name1 -Dtarget.profile.evn=dev
Fail CMD: ant
<project name="MyProject" default="myTarget" basedir=".">
<target name="checkParams">
<condition property="isReqParamsProvided">
<and>
<isset property="clientName" /> <!-- if provide read latest else read form property tag -->
<length string="${clientName}" when="greater" length="0" />
<isset property="target.profile.evn" /> <!-- mvn clean install -Pdev -->
<length string="${target.profile.evn}" when="greater" length="0" />
</and>
</condition>
<echo>Runtime Sytem Properties:</echo>
<echo>client = ${clientName}</echo>
<echo>target.profile.evn = ${target.profile.evn}</echo>
<echo>isReqParamsProvided = ${isReqParamsProvided}</echo>
<echo>Java/JVM version: ${ant.java.version}</echo>
</target>
<target name="failOn_InSufficentParams" depends="checkParams" unless="isReqParamsProvided">
<fail>Invalid params for provided for Build.</fail>
</target>
<target name="myTarget" depends="failOn_InSufficentParams">
<echo>Build Success.</echo>
</target>
</project>