Master Spring Boot Maven Startup Parameters for Development, Testing, and Production

This guide presents a comprehensive set of methods for configuring Spring Boot Maven startup parameters—including JVM memory, active profiles, and system properties—across development, testing, and production environments, with practical examples, best‑practice recommendations, and CI/CD integration tips.

Ray's Galactic Tech
Ray's Galactic Tech
Ray's Galactic Tech
Master Spring Boot Maven Startup Parameters for Development, Testing, and Production

1. Comparison of configuration methods

The following Maven‑based approaches can be used to supply JVM arguments, Spring profiles and custom system properties to a Spring Boot application. Each method has a specific scope and trade‑off.

spring-boot-maven-plugin <jvmArguments> – Simple declarative configuration for local development. Changes require editing pom.xml and rebuilding.

maven-surefire-plugin <argLine> – Supplies JVM arguments only for the test phase (executed by mvn test).

Maven property ${jvm.arguments} – Allows the arguments to be overridden from the command line (e.g., -Djvm.arguments="-Xmx1024m") while keeping the pom clean.

Maven <profiles> – Provides separate sets of properties for dev, test and prod. The desired profile is activated with -P <profile-id>.

Command‑line -Dspring-boot.run.* – Most flexible for temporary changes or CI/CD pipelines; arguments are passed directly to the spring-boot:run goal.

systemPropertyVariables – Explicitly maps system properties (e.g., spring.profiles.active) inside the plugin configuration; requires Maven execution.

2. Common configuration techniques

2.1 Configure JVM arguments in spring-boot-maven-plugin

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <configuration>
        <jvmArguments>-Xmx512m -Xms256m -Dspring.profiles.active=dev</jvmArguments>
      </configuration>
    </plugin>
  </plugins>
</build>

2.2 Use maven-surefire-plugin for test JVM arguments

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>-Xmx512m -Dspring.profiles.active=test</argLine>
  </configuration>
</plugin>

2.3 Dynamic configuration with a Maven property

<properties>
  <jvm.arguments>-Xmx512m -Dspring.profiles.active=dev</jvm.arguments>
</properties>

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <configuration>
        <jvmArguments>${jvm.arguments}</jvmArguments>
      </configuration>
    </plugin>
  </plugins>
</build>

2.4 Define Maven profiles per environment

<profiles>
  <profile>
    <id>dev</id>
    <properties>
      <jvm.arguments>-Xmx512m -Dspring.profiles.active=dev</jvm.arguments>
    </properties>
  </profile>
  <profile>
    <id>prod</id>
    <properties>
      <jvm.arguments>-Xmx1024m -Dspring.profiles.active=prod</jvm.arguments>
    </properties>
  </profile>
</profiles>

Activate a profile with mvn spring-boot:run -P dev (or -P prod).

2.5 Pass arguments directly on the command line

# JVM memory
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xmx512m -Xms256m"

# Spring profile
mvn spring-boot:run -Dspring-boot.run.profiles=dev

# Application arguments (mapped to <code>String[] args</code>)
mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8085 --debug"

2.6 Configure system properties via systemPropertyVariables

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <systemPropertyVariables>
      <spring.profiles.active>dev</spring.profiles.active>
      <my.custom.property>value</my.custom.property>
    </systemPropertyVariables>
  </configuration>
</plugin>

3. Production‑ready startup

In production the packaged JAR is executed directly, typically from a shell or batch script. This avoids Maven overhead and makes it easy to change parameters via environment variables.

java -Xmx1024m -Xms512m -Dspring.profiles.active=prod -jar app.jar

Example script fragment:

SPRING_PROFILES_ACTIVE=prod
JVM_OPTS="-Xmx1024m"
java $JVM_OPTS -Dspring.profiles.active=$SPRING_PROFILES_ACTIVE -jar app.jar

4. Injecting parameters in CI/CD pipelines

Typical usage in Jenkins, GitLab CI or similar:

mvn spring-boot:run \
  -Dspring-boot.run.profiles=$DEPLOY_ENV \
  -Dspring-boot.run.jvmArguments="$JVM_OPTS"

5. Caveats and best‑practice notes

<jvmArguments> vs <argLine> – <jvmArguments> applies to the spring-boot:run goal; <argLine> is only used by the Surefire test runner.

Prefer Maven profiles for development and testing because they keep environment‑specific settings out of the main pom.

For production, keep JVM options and the active Spring profile outside the JAR (environment variables or startup scripts) to avoid hard‑coding.

When using command‑line -Dspring-boot.run.*, be aware that long argument strings can become unwieldy; consider external script files for complex configurations.

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.

ci/cdmavenSpring BootProfilesJVM arguments
Ray's Galactic Tech
Written by

Ray's Galactic Tech

Practice together, never alone. We cover programming languages, development tools, learning methods, and pitfall notes. We simplify complex topics, guiding you from beginner to advanced. Weekly practical content—let's grow 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.