views:

36

answers:

2

I want to include this file when running locally, but exclude it when deploy. I tried the following the doesn't seem to work.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
     <version>2.3</version>
     <executions>
       <execution>
     <phase>package</phase>
     <goals>
       <goal>jar</goal>
     </goals>
     <configuration>
       <excludes>
         <exclude>filename.properties</exclude>
       </excludes>
     </configuration>
      </execution>
    </executions>
 </plugin>
A: 

You should put that property file into src/test/resources than it will be available for Unit testing etc. but it will not being deployed.

khmarbaise
The reason I don't want to put this in /src/test/resource is because when I use this as dependency in other internal projects, I don't want to copy this property file to those projects. I want to use this property file in development, but in production, I want to be able to use a different file.
Huy
Just put the other property file into src/main/resources so this would be used normally and used for deployment.
khmarbaise
the problem is I don't want to store production username/password in dev property file. that's why I need to replace with a different file when deploy.
Huy
For this purposes a profile is used which is defined in the settings.xml file in users home folder.
khmarbaise
A: 

I want to use this property file in development, but in production, I want to be able to use a different file.

There are several ways to achieve this but this is a perfect use case for profiles (and optionally filtering).

The Building For Different Environments with Maven 2 page explains how you could manage different property files and use the Maven Antrun plugin to pick up the "right" one depending on the profile used.

Instead of using the Antrun plugin, you could declare environment specific values as properties in different profiles in your POM and use Maven filtering. See Using Maven profiles and resource filtering for a full example. This is especially nice if you need to protect some informations (that you can "hide" in a profile inside ~/.m2/settings.xml). See also Tips and Tricks for an illustration of this.

Or, instead of putting properties inside profiles, you could put them in "filter files" and apply the right filter depending on the profile. This is a little variation of the above solution. See A Maven2 multi-environment filter setup for an example.

Pascal Thivent