0

I need to include some stuff in my final war:

I have a situation with multi profiles files in the src/main/resources:

 configuration.properties (local)
 configuration.dev.properties
 configuration.production.properties

so, I would like that when for example '-Pproduction' is executed the file configuration.production.properties is copied in the war at the dir WEB-INF/classes and renamed as 'configuration.properties'. How can I get that?

Thanks

Randomize

Randomize
  • 8,651
  • 18
  • 78
  • 133

3 Answers3

2

I would not do it like this.

Instead, I would have a single configuration.properties, holding placeholders for the values that differ depending on the profile :

numberOfThreads=${config.numberOfThreads} # depends on the profile
foo=bar #doesnt depend on the profile

And then use the filtering capabilities of the resources plugin in order to replace the placeholder with actual values fetched from the profile:

filter-dev.properties :
    config.numberOfThreads=2
filter-prod.properties :
    config.numberOfThreads=16

And now in your pom :

<profile>
  <id>dev</id>
  <properties>
    <env>dev</env>
  </properties>
</profile>
<profile>
  <id>prod</id>
  <properties>
    <env>prod</env>
  </properties>
</profile>

<filters>
  <filter>src/main/filters/filter-${env}.properties</filter>
</filters>

<resources>
  <resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
  </resource>
</resources>
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
0

Why don't you filter them. Only one file with the name and you do:

http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

<resources>
  <resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
  </resource>
</resources>
ssedano
  • 8,322
  • 9
  • 60
  • 98
0

Resources can be included on a per-profile basis and I think it would be more elegant if you would group them by environment/profile:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>commons-logging.properties</exclude>
            </excludes>
        </resource>
        <resource>
            <directory>${env.resources.dir}</directory>
        </resource>
    </resources>
[...]
</build>
<profiles>
    <profile>
        <id>local</id>
        <properties>                
            <env.resources.dir>src/test/resources</env.resources.dir>
            [...]

What I don't know yet is if I can include sources on a per profile basis (please help out if you can :D).

Community
  • 1
  • 1
Alex Ciminian
  • 11,398
  • 15
  • 60
  • 94