Spring Dynamic Configuration, Project Packaging, and Deployment for Java Backend Applications

This article explains how to use Spring's profile‑specific configuration files, package a multi‑module Java project with Maven or IDEA, and deploy the resulting JAR on a Linux server by installing JDK, setting environment variables, and starting the application in foreground or background.

Top Architect
Top Architect
Top Architect
Spring Dynamic Configuration, Project Packaging, and Deployment for Java Backend Applications

1. Dynamic Configuration Files

In enterprise development different environments (dev, test, prod) require different database and middleware settings. Spring allows specifying which application‑*.yml files to load at startup via profiles, avoiding manual edits.

Typical file naming:

application.yml
application‑druid.yml

Copy them to application‑prod.yml and application‑druid‑prod.yml for the production environment. If no profile is specified, Spring loads application.yml by default.

1.2 Startup Methods

1.2.1 Jar Startup

Run the JAR with the desired profiles:

java -jar xxx.jar --spring.profiles.active=prod,druid-prod
Note: multiple profiles are separated by commas. When the profile is set on the command line, the spring.profiles.active entry in the YAML file is ignored.

1.2.2 IDEA Startup Configuration

Open Run → Edit Configurations…

Select the Spring Boot configuration (e.g., MyProjectServerApplication)

In the “Active profiles” field enter prod, druid‑prod Apply and run.

2. Project Packaging

The project consists of three modules: my‑project‑server (service), my‑project‑dependencies , and my‑project‑common . Install the two dependency modules locally before packaging the server.

2.1 IDEA Packaging

Open the Maven view, expand the module.

Run lifecycle goals: clean, install, package.

2.2 Maven Command Packaging

Create a bin/package.bat script:

cd ..
cd my-project-dependencies
call mvn install
cd ..
cd my-project-common
call mvn clean install -Dmaven.test.skip=true
cd ..
cd my-project-server
call mvn clean package -Dmaven.test.skip=true
cd ..

Execute the script to build the JAR.

3. Project Deployment

After packaging, the JAR appears in the target directory. Deploy it to a Linux server.

3.1 Install Java Runtime

Download JDK 8 from Oracle, extract, and set system variables:

mkdir -p /usr/local/java
# extract tar.gz
export JAVA_HOME=/usr/local/java/jdk1.8.0_341
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin

Source /etc/profile to apply.

3.2 Start the Application

Foreground (logs shown, stops with Ctrl+C): java -jar my-project-server-1.0.0-SNAPSHOT.jar Foreground with background (&): java -jar my-project-server-1.0.0-SNAPSHOT.jar & Background using nohup (recommended): nohup java -jar my-project-server-1.0.0-SNAPSHOT.jar & After the service starts, access the API, e.g., http://IP:8899/sys-user/get/all .

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.

JavaBackend DevelopmentDeploymentspringDynamic Configurationmaven
Top Architect
Written by

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.

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.