Spring Boot Packaging with Maven Profiles and a Shell Deployment Tool

This article explains how to package a Spring Boot application using Maven profiles and the maven‑assembly‑plugin, generate a zip release, and deploy it on Linux with a reusable shell script that handles unzip, start, stop, and restart operations.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Spring Boot Packaging with Maven Profiles and a Shell Deployment Tool

This guide demonstrates how to package a Spring Boot project by leveraging Maven profiles to separate environment‑specific configurations and using the maven-assembly-plugin to create a zip distribution that includes the compiled JAR, configuration files, and deployment scripts.

Profiles for different environments – Define multiple <profile> entries in the Maven pom.xml (e.g., node, node1, node2) and set properties such as activeProfile, package-name, and boot-main. These properties are later substituted into the assembly descriptor and the shell script.

Maven Assembly Plugin configuration – The plugin is configured to produce a zip file ( formats node) that bundles:

A conf directory with the selected profile’s configuration files.

A lib directory containing all project dependencies.

The compiled JAR placed under ${package-name}-${activeProfile}.

The deployment script shenniu_publish.sh with executable permissions ( fileMode set to 777).

Key nodes such as mainClass, excludes, and descriptor are highlighted to control what gets packaged and how the startup class is specified.

Shell script shenniu_publish.sh – The script provides functions to unzip the package, detect running processes, start the application (supporting java -cp and java -jar modes), stop it, and restart it. Important variables ( package-name, activeProfile, boot-main) are injected from Maven properties, so the script does not need manual edits.

#!/usr/bin/env bash
# ... (full script content as shown in the source) ...
fi

Usage on Linux – After uploading the zip, unzip it, optionally convert the script to Unix line endings with vim set ff=unix, then run commands such as ./shenniu_publish.sh start, stop, restart, or unzip to automate deployment.

The article concludes with a reminder that the script can be adapted for other Java or .NET services and encourages readers to explore the provided GitHub repository for a complete example.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DeploymentmavenLinuxSpring Bootshell scriptProfilesAssembly plugin
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.