You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by xsli2 <xs...@yahoo.com> on 2012/01/11 21:05:56 UTC
One Ant buildfile calling its subdir buildfile, how to change the
base dir?
After some investigation, I would like to re-phrase my question. Here are my
files:
main/build.xml containing a target invoking a target in sub directory
<target name="test-sub">
<echo message="main base dir=${basedir}" />
<ant dir="./sub" inheritall="false" target="MyTest"/>
<subant target="MyTest" genericantfile="sub/build.xml">
<dirset dir="." includes="sub" />
</subant>
</target>
main/sub/build.xml --> containing a target "MyTest" running a JUnit test --
calling A.B.C.MyTest class
<echo message="sub base dir=${basedir}" />
<target name="MyTest">
<junit>
<classpath refid="project.classpath" />
<formatter type="brief" usefile="false" />
<test name="A.B.C.MyTest" />
</junit>
</target>
Inside MyTest.java, I added this print out:
final String currentDir = new File(".").getAbsolutePath();
System.out.println("currentDir=" + currentDir);
Running the target MyTest at main/sub is *fine*, with these printout:
[echo] sub base dir=/xxx/xx/main/sub
MyTest:
[junit] currentDir=/xxx/xx/main/sub/. <------The printout in MyTest
shows that it is run at main/sub, so inside MyTest, a relative path is
correct
Running the target test-sub at main is *bad*, with these printout:
test-sub:
[echo] main base dir=/xxx/xx/main
[echo] sub base dir=/xxx/xx/main/sub/. <--- the echo from sub/build.xml
shows that the base dir is already main/sub, not main/, however, MyTest is
still run at main/, not main/sub
MyTest:
[junit] currentDir=/xxx/xx/main/. <------The printout in MyTest shows
that it is still be run at main/, not main/sub, so inside MyTest, a relative
path becomes invalid
Thank you very much.
--
View this message in context: http://ant.1045680.n5.nabble.com/One-Ant-buildfile-calling-its-subdir-buildfile-how-to-change-the-base-dir-tp5137885p5137885.html
Sent from the Ant - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: One Ant buildfile calling its subdir buildfile, how to change the base dir?
Posted by Stefan Bodewig <bo...@apache.org>.
On 2012-01-11, xsli2 wrote:
> <echo message="sub base dir=${basedir}" />
> <target name="MyTest">
> <junit>
> <classpath refid="project.classpath" />
> <formatter type="brief" usefile="false" />
> <test name="A.B.C.MyTest" />
> </junit>
> </target>
> Inside MyTest.java, I added this print out:
> final String currentDir = new File(".").getAbsolutePath();
> System.out.println("currentDir=" + currentDir);
Ant's basedir and the running Java process' current working directory
are not the same thing. When you use an <ant> task you only change the
basedir but not the current working directory. To do that, you'd have
to fork the Java/JUnit process so it is running in a fresh Java VM.
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org