1

I would like to fill a property file common.properties with values depending environment profiles (dev, prod...) but I don't want the file being added in the classpath.

I read several topics like read Maven variable from properties file using profile

So I manage to fill the properties with a profile:

<profiles>
    <profile>
    <id>dev</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <build>
        <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <version>${properties-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <id>read-project-properties</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>read-project-properties</goal>
                        </goals>    
                        <configuration>
                            <files>
                                <file>config/common_dev.properties</file>
                            </files>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    </profile>
</profiles>

<build>
    <resources>
        <resource>
            <directory>config</directory>
            <filtering>true</filtering>
        </resource>
        ...
    </resources>
    ...
</build>

in the module I have a folder config containing the files common.properties and common_dev.properties:

common_dev.properties:
    common.reception.directory.norm = PHASE1V1
common.properties:
    common.reception.directory.norm = ${common.reception.directory.norm}

The common.properties is well filled with mvn clean install, but the config directory becomes a source folder in Eclipse, a classpath entry for the directory had been added. Which is my problem, the common.properties file is got in the application with environnement variable containing its path and not read from the classpath. It's working but confusing for project developers.

I tried also to use write-project-properties and write-active-profile-properties of properties-maven-plugin but first one write all my project properties in the file, and second one write nothing, because read-project-properties read the properties as project properties and not profile properties.

Is there a way to do what I would like to do ?

Community
  • 1
  • 1
Jeremy
  • 11
  • 2
  • I would argue that it is a better practice to have your project only contain configuration settings needed to run tests (with these settings located in src/test/resources). Environment specific settings are mostly safely configured when they are brought in at runtime external to your project (ideally the environment itself provides the configuration. For example: your application server could have a system property with the location of a properties file containing environment specific settings. – Allen Parslow Dec 07 '12 at 14:59

1 Answers1

0

Can you try using maven eclipse plugin to specifically configure eclipse to exclude the particular folder/file.

appbootup
  • 9,537
  • 3
  • 33
  • 65