How To Change Maven's Default Resource Folder

By , 31 August 2012

How To Change Maven's Default Resource Folder

Sometimes it's nice to have your projects resource files alongside the java source files they're related to. By default, Maven forces you to have a separate resource tree so, for example, whenever you need to a add a String for internationalization you have to go digging through your project's folders.

The good news is, you can change change maven's default resource folder this with this little bit of XML magic in Maven pom.xml.

  <build>
    <resources>
      <resource>
        <directory>src/main/java</directory>
        <excludes><exclude>**/*.java</exclude></excludes>
      </resource>
    </resources>
  </build>

Note this overrides the default location, so make sure src/main/resources is empty, or add to the pom.xml like this.

  <build>
    <resources>
      <resource>
        <directory>src/main/java</directory>
        <excludes><exclude>**/*.java</exclude></excludes>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
    </resources>
  </build>

Don't forget to exclude the java files unless you want to ship your source code!

How To Change Maven's Default Resource Folder

About I Like Spam

How To Change Maven's Default Resource Folder

Leave a Comment

Please visit https://ilikespam.com/how-to-change-mavens-default-resource-folder to add your comments.

Comment posted by: Daniel, last year

Really nice information, is there a way to include the dependency project property files ?
How to include the property files of dependency project ?
I am trying to get the property files of dependency project but it doesn't add in the final jar file. Currently i am adding those files after the deployment.

Comment posted by: sonia, last year

Hi,

in my case, it is not building the java files.only adding the folder.

folder structure :

src/test/java

changes in my pom.xml :

<resources>
      <resource>
        <directory>src/test/java</directory>
        <excludes><exclude>**/*.java</exclude></excludes>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
    </resources>