我正在使用Maven 3.0.3。我需要在脚本中定义一个变量(“env”)。我在我的POM一个<profiles>
部分中,我每<profile>
元素定义变量...默认激活配置文件
<profile>
<id>qa</id>
<properties>
<env>qa</env>
...
</properties>
</profile>
在我的pom.xml中,我该如何启动情景只有在通过“-P”没有指定命令行选项(并因此设置变量,如果它没有定义)?我试过下面,
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>env</name>
<value>dev</value>
</property>
</activation>
<properties>
<url>http://localhost:8080/manager</url>
<server>nnadbmon-dev-tomcat</server>
</properties>
</profile>
但在运行命令“MVN编译”失败,因为执法者的插件我设置需要我定义“ENV”变量。下面是我为我的实施者插件运行代码...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>enforce-property</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireProperty>
<property>env</property>
<message>Environment missing. This should be either dev, qa, or prod, specified as part of the profile (pass this as a parameter after -P).</message>
<regex>^(dev|qa|production)$</regex>
<regexMessage>Incorrect environment. Expecting one of dev, qa, or prod.</regexMessage>
</requireProperty>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
目前尚不清楚你想要什么。你想只提供'env'属性的默认值吗? – bmargulies
是的,我想为env属性提供默认值。 – Dave
请发布您的执行者配置。实际上,您没有定义'env'属性。如果这样的属性恰好存在并具有一定的价值,您只需设置一个配置文件即可运行。您可以使用其他值将默认env属性添加到properties元素。 – bmargulies