<profile>在pom中添加一组适当的条目,并在以下列表中包含所需的变量<properties>:
<profile>
<id>Dev</id>
<properties>
<proxyServer>dev.proxy.host</proxyServer>
<proxyPort>1234</proxyPort>
</properties>
</profile>
<profile>
<id>QA</id>
<properties>
<proxyServer>QA.PROXY.NET</proxyServer>
<proxyPort>8888</proxyPort>
</properties>
</profile>
<profile>
<id>Prod</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<proxyServer>PROD.PROXY.NET</proxyServer>
<proxyPort>8080</proxyPort>
</properties>
</profile>
Run Code Online (Sandbox Code Playgroud)
请注意,该Prod配置文件已被标记:<activeByDefault>.
在属性文件中,使用pom样式的变量分界来添加变量值占位符,匹配<property>pom中使用的标记名称:
proxyServer=${proxyServer}
proxyPort=${proxyPort}
Run Code Online (Sandbox Code Playgroud)
在pom的<build>部分中,添加一个<resources>条目(假设您的属性位于src/main/resources目录中),包含一个<filtering>标记,并将值设置为true:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>settings.properties</include>
</includes>
</resource>
</resources>
Run Code Online (Sandbox Code Playgroud)
然后,当您运行Maven构建时,划分的属性值将替换为pom <profile>条目中定义的值.
| 归档时间: |
|
| 查看次数: |
14929 次 |
| 最近记录: |