Spring Boot Packaging with Maven Assembly Plugin and shenniu_publish.sh Deployment Script
This article demonstrates how to package a Spring Boot application using Maven profiles and the Maven Assembly Plugin to create a zip release, and provides a reusable shell script (shenniu_publish.sh) for extracting, starting, stopping, and restarting the service on Linux.
The author shares a practical guide for building and deploying a Spring Boot service. It starts by explaining how to use Maven <profiles> to define environment‑specific configurations such as activeProfile , package-name , and boot-main .
Next, the maven-assembly-plugin is configured to produce a zip archive that contains the compiled jar, a conf directory with configuration files, and a scripts directory with the deployment script. The relevant Maven snippets are:
<profiles>
<profile>
<id>node</id>
<properties>
<activeProfile>node</activeProfile>
<package-name>${scripts_packageName}</package-name>
<boot-main>${scripts_bootMain}</boot-main>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
... (other profiles) ...
</profiles>The Assembly plugin configuration ( assembly.xml ) defines the zip format, disables the base directory, and specifies dependencySet and fileSet entries to include the lib jars, configuration files, the shell script (with 777 permissions), and the built jar:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" ...>
<id>${activeProfile}</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>${package-name}-${activeProfile}/lib</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/profiles/${activeProfile}</directory>
<outputDirectory>${package-name}-${activeProfile}/conf</outputDirectory>
<includes><include>**/*</include></includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/main/scripts</directory>
<outputDirectory></outputDirectory>
<includes><include>**/*</include></includes>
<fileMode>777</fileMode>
<directoryMode>777</directoryMode>
<filtered>true</filtered>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>${package-name}-${activeProfile}/</outputDirectory>
<includes><include>*.jar</include></includes>
</fileSet>
</fileSets>
</assembly>After building the zip, the author provides the shenniu_publish.sh script, which can unzip the package, set execution permissions, and manage the Java process. Key functions include shenniu_unzip , getPid , start , stop , and a command‑dispatch block handling start , stop , restart , and unzip actions.
#!/usr/bin/env bash
# variables passed from Maven
languageType="javac"
baseZipName="${package-name}-${activeProfile}"
packageName="${package-name}"
mainclass="${boot-main}"
... (rest of the script as shown in the article) ...The script is invoked on the target Linux host, optionally converting line endings with vim set ff=unix . Typical usage examples are:
./shenniu_publish.sh unzip – unzip and then start the service.
./shenniu_publish.sh start – start the jar.
./shenniu_publish.sh stop – stop the running process.
./shenniu_publish.sh restart – restart the service.
Finally, the article points to a GitHub repository containing the full project and encourages readers to explore the script for their own deployment needs.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
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.