Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Tuesday, October 16, 2012

Maven Build Script setup for various configurations

Steps to include a jar in the EAR package while building:
Scenario 1. If the jar project is part of same EAR project heirarchy and need to build before packaging
Follow the steps given here:
step1: Add plugin maven-ear-plugin
step2: Add <configuration> block, add <modules> as follows:
 <configuration>
  <modules>
   <javaModule>
    <groupId>myProjectGroup</groupId>
    <artifactId>myArtifact</artifactId>
    <bundleFileName>myArtifact-x.0.jar</bundleFileName>
    <bundleDir>[Destination-Path]</bundleDir>
   </javaModule>
  </modules>
 </configuration>
Step3: Add the dependency as follows:
 <dependency>
  <groupId>myProjectGroup</groupId>
  <artifactId>myArtifact</artifactId>
  <version>x.0</version>
  <type>jar</type>
 </dependency>
Note: Don't specify the <bundleDir> if you want the jar file to go to default folder.

Scenario 2. If the jar is external and not part of EAR project heirarchy
Follow the steps given here:
step1: Add plugin maven-ear-plugin
step2: Add <configuration> block, add <modules> as follows:
 <configuration>
  <modules>
   <javaModule>
    <groupId>externalGroup</groupId>
    <artifactId>externalJarArtifact</artifactId>
    <bundleFileName>externalJarArtifact-x.0.jar</bundleFileName>
    <bundleDir>[Destination-Path]</bundleDir>
   </javaModule>
  </modules>
 </configuration>
Step3: Add the dependency as follows:
 <dependency>
  <groupId>externalGroup</groupId>
  <artifactId>externalJarArtifact</artifactId>
  <version>x.0</version>
  <scope>system</scope>
  <systemPath>[external-jar-local-path]/externalJarArtifact-x.0.jar</systemPath>
 </dependency>
Note: Don't specify the <bundleDir> if you want the jar file to go to default folder.

Thursday, February 2, 2012

Maven build on winows and unix


Windows paths differ from that of unix, linux, solaris, aix and sometimes it becomes challange to use one pom.xml for building on two different os.
Here is how one maven script can be used for building applications on windows and unix environments:



<profiles>
    <profile>
        <id>windows</id>
        <activation>
        <os>
            <family>windows</family>
        </os>
        </activation>
        <properties>
            <!-- windows based properties here -->
        </properties>
    </profile>
    <profile>
        <id>non-windows</id>
        <activation>
        <os>
            <family>!windows</family>
        </os>
        </activation>
        <properties>
            <!-- unix based properties here -->
        </properties>
    </profile>
</profiles>

Date Time for Maven Builds

Print/View Datetime stamp in Maven
Since Maven 2.1 M1 version, here is how you can get the datetime stamp while using maven build scripts:
Define a property named "maven.build.timestamp.format" with some legitimate value i.e. "yyyyMMdd.HHmm" and property named "maven.build.timestamp" will be available to use.

Example here:



<properties>
<maven.build.timestamp.format>yyyyMMdd.HHmm</maven.build.timestamp.format>
<CurrentDateTime>${maven.build.timestamp}</CurrentDateTime>
</properties>