title: src/main/resources file overwritten by src/test/resources
body: <p>I implemented a web service using spring-boot. It reads from a file during initialization. So I created the file as <code>src/main/resources/files/init_file.txt</code>. This is a huge file and it takes a moment to read during initialization. Anyway, the web service was able to read from the file and work as expected.</p>
  
  <p>Then I added unit tests. Since this file was huge, I used a light-weight dummy file which I created as <code>src/test/resources/files/init_file.txt</code>. Note that this dummy file is in src/<strong>test</strong>/resources, and not in src/<strong>main</strong>/resources.</p>
  
  <p>Unit tests worked as expected. However, now when I run the service (<code>mvn exec:java</code>), the service always reads the dummy file from test resources.</p>
  
  <p>How can I ensure that the web service reads the correct file?</p>
  
  <p>Excerpt from <code>pom.xml</code>:</p>
  
  <pre><code>&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;artifactId&gt;myproj-main&lt;/artifactId&gt;
  &lt;name&gt;myproj : Main&lt;/name&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  
  
  
  &lt;build&gt;
  &lt;resources&gt;
    &lt;resource&gt;
      &lt;directory&gt;src/main/resources/&lt;/directory&gt;
      &lt;excludes&gt;
        &lt;exclude&gt;version.properties&lt;/exclude&gt;
        &lt;exclude&gt;conf/**&lt;/exclude&gt;
      &lt;/excludes&gt;
      &lt;filtering&gt;false&lt;/filtering&gt;
    &lt;/resource&gt;
    &lt;resource&gt;
      &lt;directory&gt;src/main/resources/&lt;/directory&gt;
      &lt;includes&gt;
        &lt;include&gt;version.properties&lt;/include&gt;
      &lt;/includes&gt;
      &lt;filtering&gt;true&lt;/filtering&gt;
    &lt;/resource&gt;
  
    &lt;resource&gt;
      &lt;directory&gt;src/main/config&lt;/directory&gt;
      &lt;includes&gt;
        &lt;include&gt;static.properties&lt;/include&gt;
      &lt;/includes&gt;
      &lt;filtering&gt;true&lt;/filtering&gt;
    &lt;/resource&gt;
  
    &lt;resource&gt;
      &lt;directory&gt;src/main/config/local&lt;/directory&gt;
      &lt;includes&gt;
        &lt;include&gt;application.properties&lt;/include&gt;
        &lt;include&gt;secure.properties&lt;/include&gt;
      &lt;/includes&gt;
      &lt;filtering&gt;true&lt;/filtering&gt;
    &lt;/resource&gt;
  
    &lt;resource&gt;
      &lt;directory&gt;target/generated-sources/xmlbeans/resources&lt;/directory&gt;
    &lt;/resource&gt;
  &lt;/resources&gt;
  
  &lt;plugins&gt;
    &lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-enforcer-plugin&lt;/artifactId&gt;
    &lt;/plugin&gt;
    &lt;!-- Springboot boot for maven --&gt;
    &lt;plugin&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
      &lt;configuration&gt;
        &lt;layout&gt;ZIP&lt;/layout&gt;
      &lt;/configuration&gt;
    &lt;/plugin&gt;
    &lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
      &lt;configuration&gt;
        &lt;!-- Sets the VM argument line used when unit tests are run. --&gt;
        &lt;argLine&gt;${surefireArgLine}&lt;/argLine&gt;
        &lt;excludes&gt;
          &lt;exclude&gt;**/IT*.java&lt;/exclude&gt;
        &lt;/excludes&gt;
      &lt;/configuration&gt;
    &lt;/plugin&gt;
    &lt;!--
         &lt;plugin&gt;
                    &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
                    &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
                    &lt;configuration&gt;
            &lt;propertyName&gt;surefireArgLine&lt;/propertyName&gt;
                        &lt;destFile&gt;${jacoco.out.path}${jacoco.out.file}&lt;/destFile&gt;
                    &lt;/configuration&gt;
                    &lt;executions&gt;
                        &lt;execution&gt;
                            &lt;id&gt;PRE-TEST-PARENT&lt;/id&gt;
          &lt;goals&gt;
                                &lt;goal&gt;prepare-agent&lt;/goal&gt;
                            &lt;/goals&gt;
                        &lt;/execution&gt;
                    &lt;/executions&gt;
                &lt;/plugin&gt;
    --&gt;
    &lt;!-- Copy application configurations to test resources for tests. --&gt;
    &lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
      &lt;executions&gt;
        &lt;execution&gt;
          &lt;phase&gt;process-test-resources&lt;/phase&gt;
          &lt;goals&gt;
            &lt;goal&gt;run&lt;/goal&gt;
          &lt;/goals&gt;
          &lt;configuration&gt;
            &lt;target&gt;
              &lt;!-- Include environment-invariant content from src/main/config --&gt;
              &lt;copy overwrite="true" todir="${project.build.testOutputDirectory}" verbose="true"&gt;
                &lt;fileset dir="${project.basedir}/src/main/config" includes="*"&gt;
                  &lt;type type="file"/&gt;
                  &lt;!-- don't include subfolders --&gt;
                &lt;/fileset&gt;
              &lt;/copy&gt;
  
              &lt;!-- Include environment-variant content from src/main/config/${test.config.profile}, including subfolders --&gt;
              &lt;copy overwrite="true" todir="${project.build.testOutputDirectory}" verbose="true"&gt;
                &lt;fileset dir="${project.basedir}/src/main/config/${test.config.profile}" includes="**/*"/&gt;
              &lt;/copy&gt;
            &lt;/target&gt;
          &lt;/configuration&gt;
        &lt;/execution&gt;
      &lt;/executions&gt;
    &lt;/plugin&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>I also tried using <code>&lt;excludes&gt;</code> to exclude <code>src/test/resources/*</code> but it did not work.</p>
  
  <pre><code>nik@ubuntu:myproj-main$ mvn exec:java
  [INFO] Scanning for projects...
  [INFO]                                                                         
  [INFO] ------------------------------------------------------------------------
  [INFO] Building myproj : Main 1.0.0-SNAPSHOT
  [INFO] ------------------------------------------------------------------------
  [INFO] 
  [INFO] &gt;&gt;&gt; exec-maven-plugin:1.2.1:java (default-cli) @ myproj-main &gt;&gt;&gt;
  [INFO] 
  [INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce) @ myproj-main ---
  [INFO] 
  [INFO] &lt;&lt;&lt; exec-maven-plugin:1.2.1:java (default-cli) @ myproj-main &lt;&lt;&lt;
  [INFO] 
  [INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ myproj-main ---
  
    .   ____          _            __ _ _
   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
    '  |____| .__|_| |_|_| |_\__, | / / / /
   =========|_|==============|___/=/_/_/_/
   :: Spring Boot ::        (v1.0.2.RELEASE)
  
  2015-01-23 13:05:43,101  INFO [com.mycom.comnt.Application] Starting Application on ubuntu with PID 63446 (/home/nik/work/myproj/myproj-main/target/classes started by nik in /home/nik/work/myproj/myproj-main)
  2015-01-23 13:05:43,101 DEBUG [com.mycom.comnt.Application] Running with Spring Boot v1.0.2.RELEASE, Spring v4.0.5.RELEASE
  2015-01-23 13:05:48,311  INFO [com.mycom.comnt.Application] ServletContext initialized
  2015-01-23 13:05:48,496  INFO [com.mycom.comnt.services.EventStatusService] Event availability service: found 3 available events
  2015-01-23 13:05:51,822  INFO [com.mycom.comnt.Application] Started Application in 8.896 seconds (JVM running for 11.973)
  </code></pre>