Step-by-Step Guide to Packaging and Deploying a Spring Boot Microservice with Maven
This article walks through analyzing a Spring Boot microservice project, configuring parent and child Maven pom files, packaging the required backend modules, and deploying both the backend JARs and the frontend static assets to a server using Java and http‑server.
1. Project Analysis
The example project contains both front‑end and back‑end code. Only the back‑end modules that include a main class need to be packaged. The modules are:
business : business logic interfaces
file : file upload/download APIs
gateway : request gateway, intercepts all calls
generator : code‑generation utilities
server : entity, utility, and enum classes
system : user‑related APIs
Modules that contain a Main class (business, file, gateway, system) are the ones that must be packaged.
2. Packaging the Project
2.1 Parent pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.lsu</groupId>
<artifactId>online-course</artifactId>
<packaging>pom</packaging>
<version>1.0.0</version>
<modules>
<module>system</module>
<module>gateway</module>
<module>server</module>
<module>business</module>
<module>generator</module>
<module>file</module>
</modules>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
…
</properties>
<dependencyManagement>
<dependencies>…</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>The parent pom must declare maven-compiler-plugin and maven-surefire-plugin.
Packaging type is set to pom so that building the parent triggers all child modules.
2.2 Child pom.xml (example: business module)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>online-course</artifactId>
<groupId>com.lsu</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>business</artifactId>
…
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.lsu.business.BusinessMainApplication</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>The child pom must specify the spring-boot-maven-plugin and the fully‑qualified main class.
Packaging type is jar so that a runnable JAR is produced.
2.3 Execute Packaging
Run the Maven package phase from the IDE or the command line: mvn package The parent pom builds all modules that contain a main class. After the build finishes, each packaged module appears in its target directory as a JAR file.
Start a module, for example:
java -jar business-1.0.0.jar3. Deploying the Backend
Copy the generated JAR files to the target server (Windows Server 2012, Linux, etc.) where a Java runtime is already installed. Launch the service with the same java -jar command. For Linux you can use tools like XShell to transfer files before starting.
4. Front‑End Packaging and Deployment
The front‑end project uses a multi‑environment configuration. The development environment file .env.dev contains the gateway address:
NODE_ENV=development
VUE_APP_SERVER=http://<em>your‑server‑ip</em>:9100In package.json add the --mode dev flag to the build script so that the build runs in development mode.
Build the front‑end assets (the dist folder) with the standard npm command, then serve the static files. The simplest way is to install http-server globally and run it against the dist directory:
// install http‑server globally (use cnpm if available)
cnpm install http-server -g
// serve the built files
http-serverThe server prints an HTTP address; open it in a browser to verify that the front‑end is running. Alternatively, you can configure Nginx to serve the dist directory.
Java Architect Handbook
Focused on Java interview questions and practical article sharing, covering algorithms, databases, Spring Boot, microservices, high concurrency, JVM, Docker containers, and ELK-related knowledge. Looking forward to progressing together with you.
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.
