I think, therefore I blog

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 Roger Keays

How To Change Maven's Default Resource Folder

Roger Keays is an artist, an engineer, and a student of life. Since he left Australia in 2009, he has been living as a digital nomad in over 40 different countries around the world. Roger is addicted to surfing. His other interests are music, psychology, languages, and finding good food. Click here to subscribe to his weekly blog, or stalk him on Facebook and Twitter.

Leave a Comment

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

Comment posted by: Daniel, 10 months ago

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, 10 months ago

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>

 

Join 3,559 People Who Think Outside The Box

I write every Sunday about travel, psychology, technology, and all sorts of interesting stuff. It's completely free, and you can subscribe for as long as you like. Do it now, so you don't miss a single post.

Chat For A While

Your Vote Matters

Which Tech Company is the Creepiest?
Facebook
Microsoft
Google
Amazon
Wikipedia
Wikileaks
Redtube