如何使用的build.xml设置在Java code的属性 [英] How to set a property in java code using build.xml
本文介绍了如何使用的build.xml设置在Java code的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来的蚂蚁和任何帮助将AP preciated。
I am new to Ant and any help will be appreciated.
我想要做的是:
当我调用Ant目标,我做的:
When I am invoking an Ant target, I am doing :
蚂蚁-DSIMV3.1 = TRUE运行tenantManagement
现在里面的build.xml,我有:
Now Inside build.xml, I have:
<target name="run-tenantManagement" depends="jar">
<property name="SIMV3.1" value="${SIMV3.1}" />
...
</target>
现在我想的财产SIMV3.1的价值是我的Java code内可见。
因为在我的Java code,我想设置一个条件是:
Now I want the value of the property SIMV3.1 to be visible inside my java code. Because in my java code, I want to set a condition that:
if(SIMV3.1==true){
//do something
}else{
//do something else
}
请帮助。
推荐答案
您可以在Java的Ant任务使用sysproperty的设置属性。
You can make use of sysproperty in java ant task to set the property.
<target name="run-tenantManagement" depends="jar">
<java classname="props" fork="true">
<sysproperty key="SIMV3.1"
value="${SIMV3.1}"
/>
</java>
</target>
这可以在Java类,如下读取,
This can be read in java class as below,
import java.util.Properties;
public class props {
public static void main( String[] args )
{
String testProp = "SIMV3.1";
Properties sysProps = System.getProperties();
System.out.println( "Value of " + testProp + " is " +
sysProps.getProperty(testProp) );
}
}
这篇关于如何使用的build.xml设置在Java code的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文