Maven Change a value in a file based on profile

十年热恋 提交于 2019-11-28 05:51:35

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?

Yes it is. Activate resources filtering and define the value to replace in each profile.

In your ApplicationResources.properties, declare a token to replace like this:

resources.location=${your.location}

In your POM, add a <filtering> tag for the appropriate <resource> and set it to true like this:

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

Then, add a <your.location> element within the <properties> element inside each profile:

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

More on filtering of resources here and here.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!