How to Deploy a Spring Boot Microservice Project with Maven and Nacos

This guide walks you through analyzing a Spring Boot microservice project, configuring Maven parent and child POM files, packaging the required modules, and deploying both the backend JAR and the frontend assets on Windows or Linux servers using simple command‑line tools.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
How to Deploy a Spring Boot Microservice Project with Maven and Nacos

1. Project Analysis

The example project uses Alibaba Nacos for service discovery and does not include Eureka. It contains both front‑end and back‑end code, but only the back‑end modules that have a main class need to be packaged.

business: business logic interfaces

file: file upload/download interfaces

gateway: request gateway, intercepts all traffic

generator: code‑generation utilities

server: entity, utility and enum classes

system: user‑related interfaces

Only the modules that contain a main startup class (business, file, gateway, system) need to be packaged.

2. Packaging the Project

2.1 Parent pom

<?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>
    <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 the parent aggregates all modules.

2.2 Child pom (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 spring-boot-maven-plugin and the fully qualified main class.

Packaging type is jar.

2.3 Execute packaging

Run the Maven command in IDEA or from the terminal: mvn package After packaging, the JAR files appear in each module’s target directory.

java -jar business-1.0.0.jar

3. Deploy the Project

Copy the generated JARs to a Windows Server 2012 or Linux host that already has a Java runtime, then start them with the java -jar command. The same process works for all modules.

The project is front‑end/back‑end separated. For the front‑end:

Define environment variables in .env.dev (e.g., VUE_APP_SERVER=http://<server_ip>:9100).

Add --mode dev to the npm script in package.json to run in development mode.

Build the front‑end and obtain the dist directory: npm run build --mode dev Serve the static files with a simple HTTP server (or Nginx). Example using http-server:

cnpm install http-server -g
cd dist
http-server

The console prints an access URL; opening it in a browser shows the fully deployed application.

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.

javamavenSpring Boot
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

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.