New to Ant - Problem with relative paths
Asked Answered
F

1

8

Please help, I'm going slightly mad!!

I'm using Eclipse-generated antfiles to build a project with dependencies, one of which has its own buildfile in a directory which is a sibling to the direct ancestor of the project I'm building. E.g. if my directory is "/base/modules/clinicalcontext", the directory of one of the dependencies is simply "/base/core".

So, the generated build.xml uses ../../core which afaik is correct. But it is not!! From the console it is apparent that Ant goes back three levels and not just two (it gives FileNotFound on "/core/build.xml").

I tried to change the relative path to "../core" and much to my astonishment, this way Ant goes back by one level (it laments "/base/modules/core" being nonexistent). So how in the world I tell Ant t go back by two levels? I'd prefer to avoid using absolute paths, since I might have to move the project to a different machine someday.

Thanks everybody.

Foliate answered 3/12, 2009 at 14:25 Comment(0)
M
10

All Ant path will be relative to your current working directory.

So, check what directory you are running your script from.

I suggest that you start using ${basedir} to get a path relative to a location of build.xml.

In your case, the relative path should be constructed like this: ${basedir}/../../core, instead of ../../core.

The inconsistencies you encounter illustrate a point why eclipse-generated ant scripts are a good starting point, but never a good project build system.

EDIT. I wonder why eclipse ant generator does not insert ${basedir} in relative paths? Maybe you should report it as a bug.

Misgiving answered 3/12, 2009 at 14:56 Comment(4)
${basedir} is correctly set to . which is also the location of the buildfile I'm using.Foliate
Yes, but the path like this ( ../../core ) is not relative to a basedir. ../../core is dependent on your CWD, ${basedir}/../../core is not.Misgiving
That did it, thanks! I didn't consider that buildfiles of dependencies would not change the CWD.Foliate
I am calling an ant-task from another ant-task, but basedir seems to be relative to the build-file that started the build, not the one being executed actually...Brazell

© 2022 - 2024 — McMap. All rights reserved.