DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Leveraging FastAPI for Building Secure and High-Performance Banking APIs
  • Introduction to Apache Camel
  • How To Ensure Fast JOIN Queries for Self-Service Business Intelligence
  • Idempotent Liquibase Changesets

Trending

  • Leveraging FastAPI for Building Secure and High-Performance Banking APIs
  • Introduction to Apache Camel
  • How To Ensure Fast JOIN Queries for Self-Service Business Intelligence
  • Idempotent Liquibase Changesets
  1. DZone
  2. Coding
  3. Java
  4. Maven - In Real Time

Maven - In Real Time

Karthikeyan Kanagaraj user avatar by
Karthikeyan Kanagaraj
·
Jun. 14, 12 · News
Like (0)
Save
Tweet
Share
13.47K Views

Join the DZone community and get the full member experience.

Join For Free
A perfect dependency management tool that most of us have used in our projects.

I would like to share some real-time problem scenarios that Maven is able to address pretty well.

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

After doing is routine tasks, he was frustated due to the increasing work load because of multiple OS and 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 founfd it to be Maven... 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 inculded/excluded for build (optional java files includes & excludes)
   * Activation based on various JDK version/OS version/Property(only System Property)

Lets see a quick snapshot of Pom,

<project 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.0 http://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>
<jdk>1.5</jdk> <!--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 managment :) :)
Apache Maven

Opinions expressed by DZone contributors are their own.

Trending

  • Leveraging FastAPI for Building Secure and High-Performance Banking APIs
  • Introduction to Apache Camel
  • How To Ensure Fast JOIN Queries for Self-Service Business Intelligence
  • Idempotent Liquibase Changesets

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: