views:

384

answers:

2

I have the following use case: My application is started with an Ant Script, which asks the user several questions about the project configuration (database settings etc.). These settings are stored in a properties-file.

Then i want to run Maven from within my Ant script by Maven Ant Tasks, which should replace the pre-defined properties in my pom.xml with the properties of the properties-file. I don't want to change the pom.xml.

Is there a way to do this? Thanks in advance!

(BTW i already tried a similar approach with maven only, which seems to be impossible at the moment)

+1  A: 

You can redefine the properties on the maven command line using -D and these will override the properties in your project file.

For example, in pom.xml

  <properties>
     <myProp>A</myProp>
  </properties>

In your ant build.xml, you can then invoke the mvn command line like

mvn -DmyProp=B install

which Will set myProp to B in the project. The mvn ant task page discusses using a macro to invoke the maven commandline. This can be easily customized to also pass the additional properties.

To do this in maven alone, use the exec plugin to launch maven, passing the command parameters in the same way as done using the ant:java task.

mdma
+1  A: 

Did you try to replace the properties on the fly through <copy> ant task ?

Assume your properties are in file settings.properties. Define the properties to replace in your pom.xml with @ around them, you can copy the pom file and substitute some properties at the same time. E.g.:

<copy file='pom.xml' toFile='real-pom.xml'>
  <filterset filtersfile='settings.properties' />
</copy>

Then you invoke maven:

mvn -f real-pom.xml

kabado