When invoking <java> task under ant, system props do not seem to beinherited as the docs imply they

  • Thread starter christopherLeeBedford
  • Start date
C

christopherLeeBedford

Hi, I am pretty sure this is a bug, but maybe someone can point out
something i overlooked. many thanks, in advance, for your help...

I have a very simple java file 'PropTest.java' that prints out the
value of the system property 'prop'. When i run the test from the
command line (using java command and -Dprop=somevalue), I see that the
value that I set for 'prop' is indeed dumped out.

But when I set up a simple ant build.xml file to invoke the program
via the <java> task it appears that the value of the system property
that i set on the command line is not propagated... It seems that it
is somehow swallowed and lost by ant.

Below you will find examples of the runs of the program via ant
and via the 'java' command.

Below the run output you will find the source code for these very
simple test cases.


RUN OUTPUT
-----------

------------------------->>>> java -Dprop=blah PropTest #
INPUT, corresponding output follows on next line
property: blah


------------------------->>>>> ant -Dprop=blah run #
INPUT, corresponding output follows on next line
Searching for build.xml ...
Buildfile: /home/cbedford/.hudson/jobs/
cbedford.KMIGRATE.javaOnly.cbedford-linux.mygazoo.com.12753/workspace/
kernel/platform/functionaltest/src/java/build.xml

run:
[echo] dumping out value of property in ant, right before
invoking java task: blah
[java] property: null

BUILD SUCCESSFUL

------------------------->>>> ant -version #
INPUT, corresponding output follows on next line
Apache Ant version 1.7.0 compiled on December 13 2006




SOURCE CODE
-----------

public class PropTest {
public static void main(String[] args) {
String propValue = System.getProperty("prop");
System.out.println("property: " + propValue );
}
}


build.xml
---------
<project name="demo" default="run" basedir="." >
<path id="classpath.runjava">
<path location="${basedir}"/>
</path>

<target name="run" >
<echo level="info" message=" dumping out value of property in
ant, right before invoking java task: ${prop}"/>
<!-- tried fork="false".. had no effect...
<java classname="PropTest" fork="false">
-->
<!-- tried it without clonevm, had no effect...
<java classname="PropTest" fork="false">
-->
<!-- tried it with clonevm=true, no fork specified... had no
effect.
<java classname="PropTest" fork="false">
-->

<java classname="PropTest" clonevm="true" fork="true">
<classpath refid="classpath.runjava"/>
</java>
</target>
</project>


Relevant Documentation:

http://ant.apache.org/manual/CoreTasks/java.html

Particularly relevant on this page is the text which reads:

clonevm If set to true true, then all system properties and
the bootclasspath of the forked Java Virtual Machine will be the
same as those of the Java VM running Ant. Default is
"false" (ignored if fork is disabled). since Ant 1.7
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top