A maven project that have multiple property files via maven antrun plugin
Tech-Today

A maven project that have multiple property files via maven antrun plugin


This tutorial will answer several questions (below) within a maven project that has several configuration files (dataset, property, persistence).

1.) How to have multiple persistence, datasource and property files depending on the profile or environment variable (xxx-dev, xxx-integr, xxx-prod)?

2.) How to execute a maven copy/rename/move in a pom?

3.) How to execute an ant if inside a maven pom?

It's best to answer this question in this simple chunk of code :-)


<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>install</phase>
<configuration>
<target>
<echo>Execute ant tasks</echo>
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
</taskdef>
<if>
<isset property="local.tomcat.home" />
<then>
<copy
file="${project.basedir}/src/main/resources/ipiel-${env}.properties"
tofile="${local.tomcat.home}\conf\ipiel.properties" />
</then>
</if>
<copy
file="${project.basedir}/src/main/resources/META-INF/persistence-${env}.xml"
tofile="${project.build.directory}/${project.artifactId}-${project.version}/META-INF/persistence.xml" />
</target>

</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>20020829</version>
</dependency>
</dependencies>
</plugin>

Some notes:
1.) We need to define a dependency to ant-contrib to be able to use the ant if tag.
2.) The copy property file will execute if property local.tomcat.home is set.

Note, using -P production will only activate that profile but will not replace any variable in the actual property file. To be able to get the actual file we need to specify -Denv=prod. Also we need to bind it to the test phase and not the install phase.




- Wildfly Server Provisioning Elastic Search Integration
I'm interested and would like to evaluate the integration of Elasticsearch to hibernate-search. I'm using the Wildfly container, however, Wildfly's hibernate-search library is a bit outdated: 5.5.8. so I need to find a way to outdate the jars...

- How To Package A Java Standalone App Using Maven Assembly
The sample codes below will assemble a zipped package of a java standalone app. Dependencies: maven-jar-plugin - to create the jarmaven-assembly-plugin - to assemble the distribution packagepom.xml<plugin> <groupId>org.apache.maven.plugins</groupId>...

- How To Create A Modularized Ear Project In Maven
This post is one way of creating a typical javaee6 maven project that contains ear, web, ejb and api. The output of course is an ear file that contains (web, ejb and api). How it looks like (assuming our top project is named ipiel): +ipiel  +ipiel-ear...

- How To Generate Wadl Via Maven Plugin
So you've written your web service and would now want to create the wadl for it.  Assuming you have your web project in eclipse with maven integrated this is what you have to do: 1.) Add the lines below to your pom, you may want to create it's...

- How To Get Git Build Id Using Maven
There are times when git's build number is important for a release. Specially in development mode, when there are frequent releases. So if we want to append the build number on our page, how do we automate it? For us to achieve this we will need 2...



Tech-Today








.