maven-2 - Maven 根据配置文件更改文件中的值

标签 maven-2 profiles

我的应用程序中有一个名为 ApplicationResources.properties 的属性文件,其中的属性会根据环境而变化。假设该属性是:

     resources.location=/home/username/resources

当应用程序在开发期间执行时和应用程序投入生产时,该值是不同的。

我知道我可以在 Maven 中使用不同的配置文件在不同的环境中执行不同的构建任务。我想要做的是根据正在使用的 Maven 配置文件以某种方式替换属性文件中 resources.location 的值。这可能吗?

最佳答案

What I want to do is somehow replace the value of the resources.location in the properties file based on the Maven profile in use. Is this even possible?

是的。激活资源过滤并定义每个配置文件中要替换的值。

在您的 ApplicationResources.properties 中,声明一个要替换的 token ,如下所示:

resources.location=${your.location}

在您的 POM 中,添加 <filtering>适当的标签<resource>并将其设置为 true,如下所示:

<project>
  ...
  <build>
    ...
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
      ...
    </resources>
    ...
  </build>
  ...
</project>

然后,添加 <your.location> <properties> 内的元素每个配置文件内的元素:

<project>
  ...
  <profiles>
    <profile>
      <id>my-profile</id>
      ...
      <properties>
        <your.location>/home/username/resources</your.location>
      </properties>
      ...
    </profile>
    ...
  </profiles>
</project>

有关资源过滤的更多信息 herehere .

关于maven-2 - Maven 根据配置文件更改文件中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2335431/

相关文章:

maven-2 - Maven : Using inherited property in dependency classifier causes build failure

google-analytics - Analytics(分析)配置文件过滤器-自定义字段

maven-2 - Maven 项目 - github

maven-2 - 是否可以选择性地生成程序集?

Java EE 在 Hudson/Jenkins 中提供依赖项

maven-2 - 在当前项目和插件组中找不到前缀 'C' 的插件

java - 尝试使用 Hudson 运行 Selenium 测试 - "Error: no display specified"

spring-batch - Spring 批处理中的型材

java - Spring 3.1 中的默认配置文件

MySQL:我在网站中的哪里存储每个用户的个人资料信息?