Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude application.properties when generating war using spring boot and spring-boot-maven-plugin

I am developing a web application using Spring Boot, and want to generate war instead of jar.

It works very fine using the conversion from jar to war described here : http://spring.io/guides/gs/convert-jar-to-war/

But I want to exclude the application.properties from the war, because I use @PropertySource(value = "file:${OPENSHIFT_DATA_DIR}/application.properties") to get the file path on production environment.

  • This method works when generating my war, but in eclipse I can't run my application because application.properties not copied at all to target/classes :

    <build>
        <resources> 
            <resource> 
                <directory>src/main/resources</directory> 
                <excludes> 
                    <exclude>application.properties</exclude> 
                </excludes> 
            </resource> 
         </resources> 
    </build>
    
  • This method doesn't work at all, I think that spring-boot-maven-plugin doesn't support packagingExcludes :

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration> 
                    <packagingExcludes>WEB-INF/classes/application.properties</packagingExcludes> 
                </configuration> 
            </plugin>
        </plugins>
    </build>
    

Have you another suggestion?

Thanks

like image 862
amgohan Avatar asked Nov 04 '14 20:11

amgohan


1 Answers

Try using the solution below. This will work:

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

If you are using the above solution , while running the project in Eclipse IDE you may get error that the properties file is not found. To get rid of this you need to add the resources folder in Run as configuration.(Run configurations... -> Classpath -> User Entries -> Advanced... -> Add Folders)

like image 108
nav3916872 Avatar answered Oct 26 '22 01:10

nav3916872