ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xsli2 <>
Subject One Ant buildfile calling its subdir buildfile, how to change the base dir?
Date Wed, 11 Jan 2012 20:05:56 GMT
After some investigation, I would like to re-phrase my question. Here are my

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" />

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">
	      <classpath refid="project.classpath" />
	      <formatter type="brief" usefile="false" />
	      <test name="A.B.C.MyTest" />
Inside, 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

    [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

Running the target test-sub at main is *bad*, with these printout:
     [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

    [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:
Sent from the Ant - Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message