CodexBloom - Programming Q&A Platform

Maven not packaging Spring Boot application correctly with custom resource filtering

πŸ‘€ Views: 1910 πŸ’¬ Answers: 1 πŸ“… Created: 2025-07-17
maven spring-boot resource-filtering Java

I'm facing an issue where my Maven build doesn't seem to package my Spring Boot application correctly, specifically with custom resource filtering. I've configured my `pom.xml` to filter resources, but the filtered properties aren't being replaced in the final JAR file. Here's what my `pom.xml` looks like: ```xml <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"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>my-spring-boot-app</artifactId> <version>1.0-SNAPSHOT</version> <properties> <env>development</env> </properties> <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </build> </project> ``` In my `application.properties` file, I have the following entry: ```properties app.env=${env} ``` However, when I build the project using `mvn clean package`, the final JAR file still contains `app.env=${env}` instead of `app.env=development`. I've tried adding the `maven-resources-plugin` to my build configuration in various ways, but nothing seems to work. Here’s what I attempted: ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.2.0</version> <executions> <execution> <id>copy-resources</id> <phase>process-resources</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/filtered-resources</outputDirectory> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins> </build> ``` I've also run `mvn clean install` and checked the contents of the JAR file and still see the unfiltered property. What am I missing here? Is there something specific about Spring Boot's default resource handling that might be interfering with the resource filtering? Any help would be appreciated!