在与Maven Ant任务运行时更改的pom.xml属性。可能吗? [英] Change properties in pom.xml at runtime with Maven Ant Tasks. Is it Possible?

查看:218
本文介绍了在与Maven Ant任务运行时更改的pom.xml属性。可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的用例:
我的应用程序在启动时Ant脚本的,它要求用户对项目配置的几个问题(数据库设置等)。这些设置存储在一个属性文件。

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.

然后我想从我的Maven的Ant任务,它应该在我的pom.xml与性能,文件的属性替换pre定义的属性Ant脚本中运行Maven。
我不想改变的pom.xml。

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!

(<一个href=\"http://stackoverflow.com/questions/2664362/properties-maven-plugin-error-loading-properties-file\">BTW我已经尝试过,只有行家了类似的做法,这似乎在此刻是不可能的)

推荐答案

您可以通过重新定义maven的命令行上的属性 -D ,这些将覆盖在属性您的项目文件。

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

例如,在pom.xml的

For example, in pom.xml

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

在您的蚂蚁的build.xml,你可以然后调用像MVN命令行

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

mvn -DmyProp=B install

这将设置myProp在项目中B点。该 MVN Ant任务页面讨论使用宏来调用命令行行家。这可以方便地定制还通过附加属性。

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.

要在行家独自做到这一点,使用 EXEC 插件推出行家,传递以同样的方式命令参数作为使用蚂蚁完成:java任务

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.

这篇关于在与Maven Ant任务运行时更改的pom.xml属性。可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆