使用Arguments配置maven配置文件

问题描述 投票:3回答:2

无论如何我可以在maven配置文件中传递参数。就像我想在特定端口上运行服务器,如果另外指定默认配置文件。就像当我运行mvn clean install -Pdeploy 4322时,应该将包部署到端口4322上运行的服务器,否则为4052。

maven maven-2 maven-3 cq5 maven-profiles
2个回答
6
投票

是的,你可以传递环境变量,如:mvn ... -Pdeploy -DdeploymentPort=4322

然后访问配置文件中的变量,如下所示:

...
<port>${deploymentPort}</port>
...

2
投票

您可以定义要在父pom.xml中使用的默认属性

 <properties>
    <crx.userId>admin</crx.userId>
    <crx.password>admin</crx.password>
    <crx.host>localhost</crx.host>
    <crx.port>4502</crx.port>
</properties>

然后在父pom.xml或子项目的pom.xml中,您可以使用这些属性。

例:

<plugin>
    <groupId>com.day.jcr.vault</groupId>
    <artifactId>content-package-maven-plugin</artifactId>
    <extensions>true</extensions>

    <configuration>
        <targetURL>http://${crx.host}:${crx.port}/crx/packmgr/service.jsp</targetURL>
        <userId>${crx.userId}</userId>
        <password>${crx.password}</password>
    </configuration>
</plugin>

然后在你的maven命令中使用-D[property name] = [value]覆盖默认值。

© www.soinside.com 2019 - 2024. All rights reserved.