我正在使用Maven 3.0.3版本。我需要在脚本中定义一个变量("env")。 我的pom文件中有<profiles>
部分,我会按照<profile>
元素来定义这个变量...
<profile>
<id>qa</id>
<properties>
<env>qa</env>
...
</properties>
</profile>
在我的pom.xml文件中,如果没有通过"-P"命令行选项指定配置文件,则如何激活profile(并在变量未定义时设置变量)?我尝试了以下内容:
<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 compile”失败了,因为我设置的执行器插件需要我定义一个“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>