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
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Maven Dependency Scope Applied
  • A Maven Story
  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin
  • Integrate Cucumber in Playwright With Java

Trending

  • Catching Data Perimeter Drift Before It Reaches Production
  • Building a Skill-Based Agentic Reviewer with Claude Code: A Practical Guide Using Skills.MD, MCP Servers, Tools, and Tasks
  • When Perfect Data Breaks: The Journey from Data Quality to Data Observability
  • Building Enterprise-Grade Real-Time IoT Dashboards with Vue 3, MQTT, and Kafka
  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.

By 
Mandar Dharurkar user avatar
Mandar Dharurkar
·
Jul. 30, 18 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
14.0K 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

  • Maven Dependency Scope Applied
  • A Maven Story
  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin
  • Integrate Cucumber in Playwright With Java

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook