在运行时使用 Maven Ant Tasks 更改 pom.xml 中的属性.是否可以? [英] Change properties in pom.xml at runtime with Maven Ant Tasks. Is it Possible?

查看:32
本文介绍了在运行时使用 Maven Ant Tasks 更改 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 Tasks 从我的 Ant 脚本中运行 Maven,这应该用属性文件的属性替换我的 pom.xml 中的预定义属性.我不想更改 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!

(顺便说一句,我已经只用 maven 尝试过类似的方法,这似乎暂时不可能)

推荐答案

您可以使用 -D 在 Maven 命令行上重新定义属性,这些属性将覆盖您项目文件中的属性.

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>

在你的 ant 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 任务页面 讨论了使用宏调用 maven 命令行.这可以轻松自定义以传递其他属性.

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.

要单独在 maven 中执行此操作,请使用 exec 插件来启动 maven,以与使用 ant: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 Tasks 更改 pom.xml 中的属性.是否可以?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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