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 Video Library
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
View Events Video Library
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
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

Migrate, Modernize and Build Java Web Apps on Azure: This live workshop will cover methods to enhance Java application development workflow.

Modern Digital Website Security: Prepare to face any form of malicious web activity and enable your sites to optimally serve your customers.

Kubernetes in the Enterprise: The latest expert insights on scaling, serverless, Kubernetes-powered AI, cluster security, FinOps, and more.

A Guide to Continuous Integration and Deployment: Learn the fundamentals and understand the use of CI/CD in your apps.

Related

  • How to Use Java to Build Single Sign-on
  • A Maven Story
  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin
  • Integrate Cucumber in Playwright With Java

Trending

  • The Advantage of Using Cache to Decouple the Frontend Code
  • Architecture Patterns: API Gateway
  • Understanding Zero Trust Security Building a Safer Digital World
  • Legacy App Migration: How Discovery Phase Speeds up Project Delivery
  1. DZone
  2. Coding
  3. Java
  4. Using Maven Profiles and Assembly Build Customized Applications

Using Maven Profiles and Assembly Build Customized Applications

Want to learn more about Maven profiling in Java? Check out this tutorial on how to use Maven profiling and assembly customized applications.

Mandar Dharurkar user avatar by
Mandar Dharurkar
·
Jul. 30, 18 · Tutorial
Like (3)
Save
Tweet
Share
13.1K Views

Join the DZone community and get the full member experience.

Join For Free

The application that my team is working on has multiple projects in it. Each project defines a distinct functionality of the application. We had to maintain distinct functionality that was separately executable and able to be merged with the main application. Because of this, the requirement was to create war files of distinct functionality projects and one deployable main war file that includes all the functionalities. We resolved this by using Maven profiles.

While creating one main deployable war file, the main concern was to create and maintain one session factory on the hibernate part that has to be used by the all dependent components. While creating a war of each distinct functionality, we included the hibernate configurations through the Maven profile, but, at the time of creation, there was one main war with dependent functionalities as a jar file. We added a common hibernate configuration file that has a reference of all dependent hibernate configurations present in each jar file through Maven profiling.

Maven Profiling

Maven profiles allow a parameterization of the build process with the purpose of making the target application portable across several deployment environments.

Project Directory Details

The main web app project includes configuration files for assembling all the dependent projects— Project 1 to 5. Each project represents a special functionality, which can be executed separately as war.

Com

-Sample-

-main web app project (war file)

-project1 (jar file)

-project2 (jar file)

-project3 (jar file)

-project4 (jar file)

-project5 (jar file)

Build Requirement

There are two requirements:

  • Build a common war file that includes all the projects

This includes the creation of jar files of a dependent project and war file that includes configurations related to a dependent project.

  • Build war of each project to execute the individual project as a separate war

This includes the creation of a war file of each dependent project separately.

Solution

We used Maven profiling to resolve this requirement. We created the tow maven profiles name ‘war’ and ‘jar,' where war profiles are set to default. When dependent projects are built using Maven, then, the war file project will be created.

When the profile is selected as a jar, then, the jar files of a dependent project are created and the war file of the main web app projects is created. This includes jar files of a dependent project. Below is the sample code.

  • Creation of Maven profiles:

Depending upon the Maven profile, the packaging type of pom.xml is selected.

A "profiles" section in the pom.xml file can contain one or more profile definitions.

<groupId>com.sample.project </groupId>
<artifactId>sampleproject</artifactId>
<version>1.0.0</version>
<name></name>
<packaging>${packaging.type}</packaging>
<url>http://maven.apache.org</url>
<!--MAVEN PROFILE + SPRING PROFILE STARTS -->
<profiles>
    <!-- profile id war : to run this application as separate war -->
    <profile>
        <id>war</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <packaging.type>war</packaging.type>
            <env.use.native.hostids>false</env.use.native.hostids>
            <env.spring.profiles>default, standlone-war</env.spring.profiles>
        </properties>
    </profile>
    <!-- profile id jar : to run this application as separate jar -->
    <profile>
        <id>jar</id>
        <properties>
            <packaging.type>jar</packaging.type>
        </properties>
    </profile>
</profiles>
<!--MAVEN PROFILE+SPRING PROFILE ENDS -->


  • Modification in Spring Configuration file
  • Below are the commands to execute both profiles
  • Using the Maven profile: war
Profile (engineering) Apache Maven application Build (game engine) WAR (file format) Assembly (CLI)

Opinions expressed by DZone contributors are their own.

Related

  • How to Use Java to Build Single Sign-on
  • A Maven Story
  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin
  • Integrate Cucumber in Playwright With Java

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
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: