You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Francisco Tolmasky <to...@gmail.com> on 2008/08/17 22:18:39 UTC

Relative Paths in Imported Files

I have a common.xml file that I import in all my build.xml throughout  
my project (subdirectories included).  One of the tasks defined in  
this common.xml has to reference a file in a java task, as so:

     <macrodef name = "my-tasl">

         <element name = "arguments"/>

         <sequential>
             <java classname = "blah..Main" >
                 <classpath>
                     <pathelement location = "../Jars/thejar.jar" />
                     <pathelement location = "." />
                 </classpath>

                 <arguments/>
             </java>
         </sequential>
     </macrodef>

Unfortunately, this only works from certain directories, since the  
pathelement location is relative.  Is there any way to make a relative  
file path from the location of the common.xml file itself?

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


Re: Relative Paths in Imported Files

Posted by Stefan Bodewig <bo...@apache.org>.
On Sun, 17 Aug 2008, Francisco Tolmasky <to...@gmail.com> wrote:

Before I answer the original question let me state that I have seen a
bug with a combination of <macrodef>, <import> and <subant> that
manifested itself as <path>-elements using the wrong basedir - I was
able to work around it by using <presetdef> instead of <macrodef>.

Unfortunately I ran out of time and some other priorities kicked in
before I could track down the problem (or even fix it).

> Is there any way to make a relative file path from the location of
> the common.xml file itself?

Yes, see the section titled "Resolving files against the imported
file" in <http://ant.apache.org/manual/CoreTasks/import.html>

Stefan

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


Re: Relative Paths in Imported Files

Posted by Peter Reilly <pe...@gmail.com>.
On Sun, Aug 17, 2008 at 9:18 PM, Francisco Tolmasky <to...@gmail.com> wrote:
> I have a common.xml file that I import in all my build.xml throughout my
> project (subdirectories included).  One of the tasks defined in this
> common.xml has to reference a file in a java task, as so:
>
>    <macrodef name = "my-tasl">
>
>        <element name = "arguments"/>
>
>        <sequential>
>            <java classname = "blah..Main" >
>                <classpath>
>                    <pathelement location = "../Jars/thejar.jar" />
>                    <pathelement location = "." />
>                </classpath>
>
>                <arguments/>
>            </java>
>        </sequential>
>    </macrodef>
>
> Unfortunately, this only works from certain directories, since the
> pathelement location is relative.  Is there any way to make a relative file
> path from the location of the common.xml file itself?

There is a magic property associated with each imported build file
which contains
the name of the build file. This is ant.file.NAME_OF_PROJECT_OF_BUILD_FILE.
This gets set if the build file has a name attribute and this name is
unique in the set
of imported build files. One can use the <dirname> task to get the directory
of the build file.

For example:

<project name="common">
   <dirname property="common.dir" file="${ant.file.common}"/>
</project>

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

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