Deploying Spring Boot Applications with Maven Assembly Plugin and a Custom Shell Script
This article explains how to package a Spring Boot application using Maven's assembly plugin, configure environment-specific profiles, and deploy the resulting zip with a custom shell script that supports start, stop, restart, and unzip operations on Linux.
This guide demonstrates a complete workflow for building and deploying a Spring Boot service. It starts by showing how to define Maven <profiles> for different environments (dev, test, uat, prod) and how to expose variables such as ${package-name} and ${boot-main} through the <properties> element.
Next, the article configures the maven-jar-plugin and maven-assembly-plugin to create a zip package that contains the compiled JAR, a conf directory with environment‑specific configuration files, and a scripts directory with a deployment script. Important plugin settings include <addClasspath>true, exclusion of resource files from the main JAR, and the <descriptor> pointing to an assembly.xml file.
The assembly.xml defines the zip structure: a lib folder for dependencies, a conf folder for configuration files, and the executable script. Nodes such as <formats>zip</formats>, <fileMode>777</fileMode>, and <filtered>true</filtered> ensure correct file permissions and variable substitution.
The core of the deployment process is the shenniu_publish.sh script. It extracts the zip, sets execution permissions, detects the running process, and provides four commands: start (supports java -cp and java -jar modes), stop, restart, and unzip. The script reads the Maven‑provided variables so no manual edits are required.
Finally, the article shows how to upload the zip to a Linux host, unzip it, and run the script (e.g., ./shenniu_publish.sh start). It also notes a common Windows‑to‑Linux line‑ending issue and provides a vim command to convert the script to Unix format. The repository URL for the full example is included.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
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.
