Change properties in pom.xml at runtime with Maven Ant Tasks. Is it Possible?

前端 未结 2 1566
渐次进展
渐次进展 2020-12-20 01:00

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.).

2条回答
  •  难免孤独
    2020-12-20 01:42

    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

      
         A
      
    

    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.

提交回复
热议问题