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.
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) ...
fiUsage 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.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.