[英]How can Ant get the value from custom Java system property
In my java class I have在我的java类中,我有
System.setProperty("test", drinks);
In my Ant build file I am able to execute the jave class.在我的 Ant 构建文件中,我能够执行 java 类。 How can I use the name "test" to get the result ${drinks} in Ant ??
如何使用名称“test”在 Ant 中获得结果 ${drinks} ?
The only way this is possible is if you use the attribute fork="false" (false being the default value) in the java Ant task.唯一可能的方法是在java Ant 任务中使用属性fork="false" (false 是默认值)。 That is, if your Java program is executed in the same JVM as Ant.
也就是说,如果您的 Java 程序与 Ant 在同一个 JVM 中执行。 Otherwise, your Java program will be executed in a separate process and none of the system properties it sets will vbe accessible to Ant.
否则,您的 Java 程序将在单独的进程中执行,并且它设置的任何系统属性都不能被 Ant 访问。 Beware, though, that executing a non-forked Java program may (and often will) have undesired side effects on the rest of the Ant build.
但是请注意,执行非分叉 Java 程序可能(并且经常会)对 Ant 构建的其余部分产生不希望的副作用。
如果在命令行中设置了该属性,例如ant -Dtest=drinks
它将作为${test}
从构建系统中可用,但是如果您通过执行 Java 代码调用此属性,则需要找到一个从生成的 Java 进程中获取值到一个新变量中的方法,通常使用System.out.println(...)
和<exec ...>
任务的outputproperty
的outputproperty
并根据需要进行解析。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.