Dynamic basedir for Ant in Eclipse

2020-06-27 06:54发布

问题:

The title might not be the best so let me explain what I am trying to do.

I have made an Ant buildfile that will help me with Maven goals. It's so much easier having to scope to Ant view and choose what I want to do. The biggest benefit with this is that I can use it in almost any project. Whether I deploy to tomcat or jboss or sakai(:deploy) or I handle mutiple instaces of the same server or skip tests... worst case I just change some path properties.

The drawback right now is that I have to keep a copy of this buildfile in every project.

What I am trying to do is have only 1 buildfile, in the workspace, and dinamicaly optain, from eclipse, the current project that I am working on. Be it module or parent I can refine that later. So basically change the basedir for ant tasks based on the selected project in eclipse.

I have tried Ant Runtime Properties but for some reason properties like

${project_path}

fail to give me what their description say. I get this:

Variable references empty selection: ${project_path}

I hope it is clear what I am trying to do. So my question, I know it's possible, I'm just missing something and I hope some of you can help me with this.

I believe the trouble is in the Ant Runtime properties. I'm not 100% sure how I should use those.

Thank you!

回答1:

EDIT after comment and further investigation..
Make the projectdir available as basedir property for ant like that :
Window > Preferences > Ant > Runtime > Properties
and create a property named basedir with value either :

${project_loc}
or
${workspace_loc}/${project_name}

and

<project basedir="${basedir}">
 <echo>$${basedir} = ${basedir}</echo>
</project>

will work as expected, means echoing eclipse/yourworkspace/projectdir

Maybe there are other ways, i.e. via Ant Addon Ant4Eclipse, which aims to make Eclipse settings available for ant, never used it.



标签: ant