3

I created a basic SpringBoot 1.5.7 app from http://start.spring.io/ (Java, Maven), and I'm working with the Eclipse project created with mvn eclipse:eclipse.

I noticed that if I modify my application.properties file and afterwards run a Junit test (all from inside Eclipse), the new version is not used.

Digging a little, I found that the new application.properties file is not copied from src/main/resources/ to target/classes/ by the Eclipse build. And it seems that the cause is that it's marked as "excluded" in the Eclipse project settings. Indeed, my (automatically generated) .classpath file says:

<classpath>
  <classpathentry kind="src" path="src/test/java" output="target/test-classes" 
     including="**/*.java"/>
  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
  <classpathentry kind="src" path="src/main/resources" 
excluding="**/*.java|**/application*.yml|**/application*.yaml|**/application*.properties"/>
  ...

Of course, the file is actually copied when I run the Maven spring-boot:run target.

Why, then, is it excluded by Eclipse's classpath? Is this right?

leonbloy
  • 73,180
  • 20
  • 142
  • 190

2 Answers2

2

It seems that mvn eclipse:eclipse is quite broken. It's better to not rely on it, simply import as Maven Project from Eclipse and be happy.

leonbloy
  • 73,180
  • 20
  • 142
  • 190
  • Even though i imported as "Maven Project" the issue still exist. If anybody using eclipse go to "Build path" and edit "src/main/resources" to include instead of excluding. It worked for me. – Sumanth Shastry Sep 17 '19 at 10:15
1

I can not tell you why, but I can tell you how to fix it :)

You need to change your configuration so that it does not filter the resource folder, such as:

<build>
        <resources>
             <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <finalName>scheduler</finalName>
                </configuration>
                 <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

This overwrites the default behaviour that I assume to be implemented in the parent pom. I will double check and raise it with the boot-guys.

Thanks,

Artur

pandaadb
  • 6,306
  • 2
  • 22
  • 41
  • Did you ever get an answer from the "boot-guys"? – KC Baltz Feb 15 '18 at 20:46
  • To be honest, I forgot. I think it might have to do with the fact that the maven eclipse plugin is retired. Filtering is turned on, yes, but properties are included by default, see: https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/pom.xml. I forgot to raise it, but I somewhat imagine that that won't be fruitful. Have you tried the eclipse m2e maven plugin (the pom is setup for that). I use the eclipse plugin from the command line. – pandaadb Feb 16 '18 at 10:15