Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #11231 > unrolled thread
| Started by | www <xsli2@yahoo.com> |
|---|---|
| First post | 2012-01-11 09:11 -0800 |
| Last post | 2012-01-11 12:00 -0800 |
| Articles | 2 — 1 participant |
Back to article view | Back to comp.lang.java.programmer
One Ant buildfile calling its subdir buildfile, how to change the base dir? www <xsli2@yahoo.com> - 2012-01-11 09:11 -0800
Re: One Ant buildfile calling its subdir buildfile, how to change the base dir? www <xsli2@yahoo.com> - 2012-01-11 12:00 -0800
| From | www <xsli2@yahoo.com> |
|---|---|
| Date | 2012-01-11 09:11 -0800 |
| Subject | One Ant buildfile calling its subdir buildfile, how to change the base dir? |
| Message-ID | <de9cbc9c-7297-43f0-847f-83b7c650c953@p4g2000vbt.googlegroups.com> |
Hi:
Here are my two build.xml files:
./A/build.xml
./A/B/build.xml
When I am at A/B/., I can run the target "test" successfully -- part
of the run include a script which contains relative path("./C/D/
my_file.txt") starting from A/B/. Again, running at B directory, the
script can locate the file it needs, which is at A/B/C/D/my_file.txt
However, I need to be able to call the same target from A/build.xml,
so I added the following inside A/build.xml:
<target name="B-test">
<ant dir="./B/" target="test">
</ant>
</target>
The error is "cannot locate the file ./C/D/my_file.txt".
Thank you for your help
[toc] | [next] | [standalone]
| From | www <xsli2@yahoo.com> |
|---|---|
| Date | 2012-01-11 12:00 -0800 |
| Message-ID | <4f3ee79e-e431-4224-a08f-973b8223aaa6@cf6g2000vbb.googlegroups.com> |
| In reply to | #11231 |
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}" />
<!--showing two tried methods below, neither one
works, all with the same error message -->
<!-- using ant task does not work -->
<ant dir="./sub" inheritall="false" target="MyTest"/>
<!-- using subant does not work either-->
<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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web