Maven – In Real Time

July 16, 2012 at 4:56 pm Leave a comment

Maven, a perfect dependency management tool ,which most of us had used in our projects.

//Here i would like to share some realtime problem scenarios where maven is able to address it pretty well.

Mr.Yan is working as a build management engineer. He takes care of the build an deploy environment in his company on daily basis.

After doing is routine tasks he was frustated due to the increasing work load because of multiple OS, Java versions. His entire day was gone in editing the property files and pom files.

Finally he started searching for a tool that would help make his work easier and atlast found it to be Maven…

So what is Maven and how it can easy his task ???

what is maven ?

maven is a build management tool. for detailed information about that, please look into

http://maven.apache.org/what-is-maven.html

After going through the documentation, he realized “Profiles” in maven can do it.

What a Maven Profile can do for us?

Maven Profile is used for the following:

* Package the Build in different formats
* Dynamically inject the dependencies
* choose which source files or resources to be included/excluded for build (optional java files includes & excludes)
* Activation of various JDK version/OS version/Property(only System Property)

Lets see a quick snapshot of Pom,

xmlns=”http://maven.apache.org/POM/4.0.0” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd“>
<modelVersion>4.0.0</modelVersion>

    <groupId>MyTest</groupId>
<artifactId>MyTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<profiles>
<profile>
<id>yan1</id>
<activation>
<activeByDefault>false</activeByDefault>
1.5 <!–this profile will be activated if the JDK is 1.5 –>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<includes> <!–can include/Exclude the sources based on the profile –>
<include>**/MyTest1.java</include>
<include>**/service/**</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies><!– we can tell the dependencies for this profile alone–></dependencies>
</profile>
<profile>
<id>yan2</id>
<activation>
<activeByDefault>false</activeByDefault>
<property><!–this profile will be activated when the system property hq.version is 2 –>
<name>hq.version</name>
<value>2</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<excludes><!–can include/Exclude the sources based on the profile –>
<exclude>**/MyTest2.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies><!– we can tell the dependencies for this profile alone–></dependencies>
</profile>
</profiles>
</project> 

This made his life easier… Now Yan wants to activate a profile and he types a simple command

mvn -P profileName

and he wants to call using properties

mvn -Dprop=value

After doing all these changes, now he is enjoying his life without any manual work in build management :) :)

Advertisements

Entry filed under: Maven. Tags: , , , , .

Java Thinking … HTTPS (SSL) Configuration : in Tomcat / Jetty / Jboss

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Blog Stats

  • 35,742 hits

%d bloggers like this: