0

I have a properties file in resource directory of my project and want to to write some property values by maven command when project build based on profile. Properties file look like this (application.properties):

server.port=${server.port}
report.workspacePath=${reporting.workspacePath}
server.path=/foo/foosame
 server.filePath=/bar/bardir

this how my pom file look like:

  <profiles>
        <profile>
            <id>server</id>
            <properties>
                <server.port>8080</server.port>
                <reporting.workspacePath>/opt/reporting/backend2-instance/reporting</reporting.workspacePath>
            </properties>
        </profile>

<profile>
            <id>staging</id>
            <properties>
                <server.port>8084</server.port>
                <reporting.workspacePath>/opt/reporting/backend1-instance/reporting</reporting.workspacePath>
            </properties>
        </profile>

        </profiles>
     <build>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <!--<excludes>
                        <exclude>*.properties</exclude>
                    </excludes> -->
                    <filtering>true</filtering>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>

                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                    <executions>
                        <execution>
                            <id>copy-resources</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>

       <outputDirectory>${basedir}/target/</outputDirectory>
                                <resources>
                                    <resource>

        <directory>src/main/resources</directory>
                                        <excludes>
                                            <exclude>*.txt</exclude>
                                        </excludes>
                                        <filtering>true</filtering>
                                    </resource>
                                </resources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

But nothing writing into properties file when i run maven command like this:

mvn -Pstaging clean package 

Can someone have clue what i am missing here.

user565
  • 871
  • 1
  • 22
  • 47
  • 1
    Possible duplicate of [How can I change a .properties file in maven depending on my profile?](https://stackoverflow.com/questions/3868310/how-can-i-change-a-properties-file-in-maven-depending-on-my-profile) – juanlumn Jan 11 '19 at 11:27
  • Perfect. So for springBoot application your properties file should be look like this @server.port@ – user565 Jan 11 '19 at 11:38
  • https://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html – user565 Jan 11 '19 at 11:38
  • You should use spring boot profiles and not Maven profiles... – khmarbaise Jan 11 '19 at 13:17

0 Answers0