ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rick Genter" <rgen...@silverlink.com>
Subject Working directory confusion
Date Tue, 01 Feb 2005 17:03:15 GMT
I'm getting confused on how the notion of "current working directory" is
maintained in ant. Here's my test script:

<?xml version="1.0"?>
<project name="test" default="all">
	<target name="all" depends="sub1, sub2"/>
	
	<target name="sub1">
		<delete dir="sub1"/>
		<mkdir dir="sub1"/>
		<copy todir="sub1" file="test.xml"/>

		<!-- use ant task -->
		<echo>Calling sub1-test via &lt;ant&gt; task:</echo>
		<ant dir="sub1" antfile="test.xml" target="sub1-test"/>

		<!-- call ant via command-line -->
		<echo>Calling sub1-test via ant.bat:</echo>
		<exec executable="cmd.exe"
		      dir="sub1">
			<arg value="/c"/>
			<arg value="call"/>
			<arg value="ant.bat"/>
			<arg value="-buildfile"/>
			<arg value="test.xml"/>
			<arg value="sub1-test"/>
		</exec>
	</target>
	
	<target name="sub1-test">
		<echo>My basedir is ${basedir}.</echo>
		<echo>My current directory is ${user.dir}.</echo>
	</target>
</project>

When I run the above (ant 1.6.2), I get:
Buildfile: C:\workspace-4\Object\test.xml
sub1:
   [delete] Deleting directory C:\workspace-4\Object\sub1
    [mkdir] Created dir: C:\workspace-4\Object\sub1
     [copy] Copying 1 file to C:\workspace-4\Object\sub1
     [echo] Calling sub1-test via <ant> task:
sub1-test:
     [echo] My basedir is C:\workspace-4\Object\sub1.
     [echo] My current directory is C:\workspace-4\Object.
     [echo] Calling sub1-test via ant.bat:
     [exec] Buildfile: test.xml
     [exec] sub1-test:
     [exec] [echo] My basedir is C:\workspace-4\Object\sub1.
     [exec] [echo] My current directory is C:\workspace-4\Object\sub1.
     [exec] BUILD SUCCESSFUL
     [exec] Total time: 0 seconds
all:
BUILD SUCCESSFUL
Total time: 1 second

Note that when invoked by the <ant> task, ${user.dir} != ${basedir}
within the <ant> task, while when invoked via the command line
${user.dir} == ${basedir}. Is there a way to get ${user.dir} ==
${basedir} using the <ant> task? (I need this so that files that are
referenced by the Java program I invoke from my <ant> task are found.)

--
Rick Genter
Principal Engineer
Silverlink Communications
<mailto:rgenter@silverlink.com>
(781) 272-3080 x242

This e-mail, including attachments, may include confidential and/or
proprietary information, and may only be used by the person or entity to
which it is addressed.  If the reader of this e-mail is not the intended
recipient or his or her authorized agent, the reader is hereby notified
that any dissemination, distribution or copying of this e-mail is
prohibited.  If you have received this e-mail in error, please notify
the sender by replying to this message and delete this e-mail
immediately.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message