eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

Partner – LambdaTest – NPI EA (cat= Testing)
announcement - icon

Distributed systems often come with complex challenges such as service-to-service communication, state management, asynchronous messaging, security, and more.

Dapr (Distributed Application Runtime) provides a set of APIs and building blocks to address these challenges, abstracting away infrastructure so we can focus on business logic.

In this tutorial, we'll focus on Dapr's pub/sub API for message brokering. Using its Spring Boot integration, we'll simplify the creation of a loosely coupled, portable, and easily testable pub/sub messaging system:

>> Flexible Pub/Sub Messaging With Spring Boot and Dapr

eBook – Maven – NPI (cat=Maven)
announcement - icon

Get up to speed with the core of Maven quickly, and then go beyond the foundations into the more powerful functionality of the build tool, such as profiles, scopes, multi-module projects and quite a bit more:

>> Download the core Maven eBook

1. Overview

Maven, a popular build and dependency manager, is widely used in Java development. Also, we can create custom properties in Maven.

When building Java applications, we often rely on properties files to store configuration values.

In this tutorial, we’ll explore how we can read an external properties file in Maven and use it effectively.

2. Introduction to the Problem

To understand the problem, let’s create a simple Maven project:

.
├── pom.xml
├── props
│   └── user.properties
└── src
    └── main
        └── resources
            └── result.txt

Since we want to focus on Maven, our project doesn’t contain any Java code. The project contains a pom.xml and a result.txt file under the src/main/resources directory.

We prepared a properties file props/user.properties:

$ cat props/user.properties
my.name=Kai
my.hobbies=Reading, Tennis, Football
my.signature=vim rocks

We’ll try to ask Maven to read this properties file when building the project.

To simply verify if Maven can load the users.properties file, we’ll first create a text file src/main/resources/result.txt with some ${…} placeholders:

Greeting message: ${greeting}
-----------------------------
Username is ${my.name}
His hobbies are ${my.hobbies}
He came in and said: "${my.signature}"

Then, we’ll leverage the resources Maven plugin, one of Maven’s core plugins, to filter the result.txt in the src/main/resources directory. It’s worth mentioning that the resources filtering is performed at the process-resources phase by default.

Next, let’s look at how we configure the resources plugin in the pom.xml file:

<project>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>${maven.resources.version}</version>
                <configuration>
                    <outputDirectory>${project.build.outputDirectory}/filtered-result</outputDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <greeting>Hi there, how are you</greeting>
    </properties>
</project>

We declare a property named greeting in pom.xml. Further, we ask the resources plugin to filter files in the src/main/resources directory and place the result under ${project.build.outputDirectory}/filtered-result.

Now, if we execute the Maven command to process-resources, Maven only knows the greeting property that we defined in the pom.xml file:

$ mvn clean process-resources
[INFO] Scanning for projects...
[INFO] ------------------< com.baeldung:external-properties >------------------
[INFO] Building external-properties 0.0.1-SNAPSHOT
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...
$ cat target/classes/filtered-result/result.txt
Greeting message: Hi there, how are you
-----------------------------
Username is ${my.name}
His hobbies are ${my.hobbies}
He came in and said: "${my.signature}"

Next, let’s see how to ask Maven to read the external properties file during the build process and make its values available for use.

3. Using the Properties Maven Plugin

The properties Maven plugin is a powerful tool for reading and injecting properties into the build process. Next, let’s see how to use this plugin to solve our problem.

3.1. Configuring the Properties Maven Plugin

First, let’s configure the properties plugin in our pom.xml file and read our user.properties file:

<project>
    <build>
        <plugins>
           <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <version>${properties.plugin.version}</version>
                <executions>
                    <execution>
                        <phase>initialize</phase>
                        <goals>
                            <goal>read-project-properties</goal>
                        </goals>
                        <configuration>
                            <files>
                                <file>${user.properties.file}</file>
                            </files>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <properties>
        <greeting>Hi there, how are you</greeting>
        <user.properties.file>props/user.properties</user.properties.file>
        <properties.plugin.version>1.2.1</properties.plugin.version>
    </properties>
</project>

As we can see, we declare the properties plugin in the <plugins> tag. Since we want to load the properties file when the build starts, we set the plugin to run the read-project-properties goal during the initialize phase.

Further, in this example, we specify the file in the <configuration> tag through an internal property, ${user.properties.file}.

Next, let’s build the project:

$ mvn clean process-resources
[INFO] Scanning for projects...
[INFO] ------------------< com.baeldung:external-properties >------------------
[INFO] Building external-properties 0.0.1-SNAPSHOT
...
[INFO] --- properties:1.2.1:read-project-properties (default) @ external-properties ---
[INFO] Loading 3 properties from File: /.../external-properties-file/props/user.properties
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...

The build log shows that the properties plugin has loaded three properties from the expected file. But let’s verify if result.txt gets filtered correctly:

$ cat target/classes/filtered-result/result.txt
Greeting message: Hi there, how are you
-----------------------------
Username is Kai
His hobbies are Reading, Tennis, Football
He came in and said: "vim rocks"

As the output shows, the build process has effectively loaded both internal and external properties.

3.2. Passing Properties File to the Maven Command Line

We’ve seen how to load an external properties file using the properties Maven plugin. However, sometimes, hardcoding the file path in pom.xml is inconvenient. For example, we may want to dynamically pick a properties file to build our project.

Let’s create a new properties file:

props
├── liam.properties
└── user.properties

$ cat props/liam.properties
my.name=Liam
my.hobbies=Music, Football, Computer Games
my.signature=Maven rocks

Now, we want Maven to load liam.properties. To achieve that, we can pass the file to the Maven command line as we build the project:

$ mvn -Duser.properties.file=props/liam.properties clean process-resources
[INFO] Scanning for projects...
[INFO] ------------------< com.baeldung:external-properties >------------------
[INFO] Building external-properties 0.0.1-SNAPSHOT
...
[INFO] --- properties:1.2.1:read-project-properties (default) @ external-properties ---
[INFO] Loading 3 properties from File: /.../external-properties-file/props/liam.properties
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...

Then, we get the expected result.txt in the target directory:

$ cat target/classes/filtered-result/result.txt
Greeting message: Hi there, how are you
-----------------------------
Username is Liam
His hobbies are Music, Football, Computer Games
He came in and said: "Maven rocks"

This approach makes the build process more flexible.

4. Conclusion

In this article, we explored how to integrate external properties into our Maven build by leveraging the properties Maven plugin. This approach helps manage environment-specific builds, ensuring our projects remain clean, maintainable, and adaptable.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

eBook Jackson – NPI EA – 3 (cat = Jackson)