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-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Reply via email to