栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

从Maven POM文件读取属性文件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从Maven POM文件读取属性文件

Maven允许您在项目的POM中定义属性。您可以使用类似于以下内容的POM文件来执行此操作:

<project>    ...    <properties>        <server.url>http://localhost:8080/manager/html</server.url>    </properties>    ...    <build>        <plugins> <plugin> ...     <configuration>         <url>${server.url}</url>         <server>tomcat</server>     </configuration> ... </plugin>        </plugins>    </build></project>

您可以避免在

properties
标记中指定属性,而将命令行中的值传递为:

mvn -Dserver.url=http://localhost:8080/manager/html some_maven_goal

现在,如果您不想从命令行指定它们,并且需要将这些属性与项目POM进一步隔离到一个属性文件中,则需要使用Properties
Maven插件
并运行它的

read-project-properties
目标在Maven生命周期的初始化阶段。此处复制了插​​件页面的示例:

<project>  <build>    <plugins>      <plugin>        <groupId>org.prehaus.mojo</groupId>        <artifactId>properties-maven-plugin</artifactId>        <version>1.0-alpha-2</version>        <executions><!-- Associate the read-project-properties goal with the initialize phase, to read the properties file. -->          <execution> <phase>initialize</phase> <goals>   <goal>read-project-properties</goal> </goals> <configuration>   <files>     <file>etc/config/dev.properties</file>   </files> </configuration>          </execution>        </executions>      </plugin>    </plugins>  </build></project>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/373995.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号