【发布时间】:2013-01-18 20:38:57
【问题描述】:
三个问题按重要性降序排列 - 链接即可。
我需要在我的 maven 插件中读取某些 maven 设置,例如 代理、服务器。我如何从我的插件中读取它们。我可以从 .m2/settings.xml 文件中读取,但我认为必须有更简单的方法(一些 API 已经做到了)。
-
我从developers cookbook看到有一个类
org.apache.maven.project.MavenProject
我需要什么依赖才能在我的插件中使用它 - 我觉得这很好。 -
是否可以在中拥有我自己的属性
settings.xml
比如说 上一页>user_name1 encrypted_password 如何?
PS:我是初学者。
更新 1
我能够在Injecting POM Properties via Settings.xml 之后创建和读取自定义属性。但是我希望有类似于cargo 提供的配置。例如
<servers>
<server>
<id>tomcat7_local</id>
<configuration>
<cargo.hostname>localhost</cargo.hostname>
<cargo.remote.uri>http://localhost:8080/manager/text</cargo.remote.uri>
<cargo.remote.username>my_username</cargo.remote.username>
<cargo.remote.password>my_password</cargo.remote.password>
<cargo.servlet.port>8080</cargo.servlet.port>
</configuration>
</server>
<server>
<id>tomcat6_local</id>
<configuration>
<cargo.hostname>localhost</cargo.hostname>
<cargo.remote.uri>http://localhost:8080/manager</cargo.remote.uri>
<cargo.remote.username>my_username</cargo.remote.username>
<cargo.remote.password>my_password</cargo.remote.password>
<cargo.servlet.port>8080</cargo.servlet.port>
</configuration>
</server>
</servers>
我如何做到这一点。对我的第三个问题有一种解决方法,不确定它是否正确。
编辑
谢谢Jordan002!我知道我可以拥有多个配置文件,但我不知道如何使用它们。这样,通过配置文件,我可以设置变量的值,或者通过说类似
的内容将值注入到我的插件中@Parameter(alias = "cargo.hostname") private String hostname;但正如我所见,对于货物插件,它所需要的所有定义如下
<servers>
<server>
<id>someId</id>
<configuration>
<!-- Configurations are placed here -->
</configuration>
</servers>
类似,或者可能不那么类似,因为这里没有配置
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>My_proxy_host</host>
<port>My_proxy_port</port>
</proxy>
</proxies>
是我可以放置 maven 使用的代理信息的地方。现在,我不想在某些 profiles 中重新定义它,也不想解析这个文件来获取信息。
此外,我想做货物正在做的事情。它让我在 servers 和项目的 pom 中编写所有配置,我只需要执行以下操作
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.server.settings>tomcat7_local</cargo.server.settings>
</properties>
</configuration>
<deployer>
<type>remote</type>
</deployer>
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<type>war</type>
<properties>
<context>${project.artifactId}</context>
</properties>
</deployable>
</deployables>
</configuration>
</plugin>
cargo 会获取我为 tomcat7_local 定义的配置,无需为此编写配置文件。
【问题讨论】:
标签: java maven maven-plugin