Wednesday, March 10, 2010

maven profiles

Tagged with: ,
Thursday, November 13, 2008, 7:00
This news item was posted in HowTo & Tutorial category and has 1 Comment so far.
Apache Maven

Image via Wikipedia

Maven profiles enable your pom to build your project with different build options .

Here I tried to overwrite some default configuration files with profile specific configuration

how to use it

mvn package -Ddevelopment

copy src/main/conf/development/mysql.properties to target/classes/META-INF/mysql.properties

mvn package -Dproduction

copy src/main/conf/development/mysql.properties to target/classes/META-INF/mysql.properties


<profiles>
<profile>
<id>development</id>
<activation>
<property>
<name>development</name>
</property>
</activation>
<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>process-resources</id>
<phase>process-resources</phase>
<configuration>
<tasks>
<taskdef name="native2ascii"
classname="org.apache.tools.ant.taskdefs.optional.Native2Ascii"
classpathref="maven.dependency.classpath">
<classpath>
<pathelement path="maven.dependency.classpath"/>
</classpath>
</taskdef>
<delete dir="${basedir}/target/classes"
includes="**/*.properties"/>
<native2ascii src="${basedir}/src/main/resources"
dest="${basedir}/target/classes"
includes="**/*.properties"
encoding="ISO-8859-9"/>
<copy file="${basedir}/src/main/conf/development/mysql.properties"
tofile="${basedir}/target/classes/META-INF/mysql.properties"
overwrite="true"/>

</tasks>

</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>

</plugin>

</plugins>
</build>

</profile>
<profile>
<id>production</id>
<activation>
<property>
<name>production</name>
</property>
</activation>
<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>process-resources</id>
<phase>process-resources</phase>
<configuration>
<tasks>
<taskdef name="native2ascii"
classname="org.apache.tools.ant.taskdefs.optional.Native2Ascii"
classpathref="maven.dependency.classpath">
<classpath>
<pathelement path="maven.dependency.classpath"/>
</classpath>
</taskdef>
<delete dir="${basedir}/target/classes"
includes="**/*.properties"/>
<native2ascii src="${basedir}/src/main/resources"
dest="${basedir}/target/classes"
includes="**/*.properties"
encoding="ISO-8859-9"/>
<copy file="${basedir}/src/main/conf/production/mysql.properties"
tofile="${basedir}/target/classes/META-INF/mysql.properties"
overwrite="true"/>
</tasks>

</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>

</plugin>

</plugins>
</build>

</profile>

</profiles>
Reblog this post [with Zemanta]
Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • Wists
  • LinkedIn
  • Slashdot
  • Google Bookmarks
  • Reddit
  • StumbleUpon
  • email
  • Twitter

Related posts:

  1. JAXB quickstart via maven2
  2. Grails Productivity Tip: Depend on Your Plugin
  3. hibernate native id generator bug 3.2.4-ga
  4. Clustering Acegi via JGroups (DistributedHashtable)
  5. hibernate native Id generator tip

You can leave a response, or trackback from your own site.

One Response to “maven profiles”

  1. David said on Wednesday, December 9, 2009, 14:57

    Hi, thank you for this simple overview, sometimes an example makes it all clear.
    Isn’t there a way to share the common configuration and define it just once? (And only define the environment specific tasks)

    ps small (copy/paste) typo found last sentence before sample:
    copy src/main/conf/development/mysql.properties to target/classes/META-INF/mysql.properties
    development must be production ;-)

Leave a Reply