Where do I put resources in my maven project?
Author: Deron Eriksson
Description: This tutorial describes where to put resources in maven projects.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)
In a project that follows the mavenSW conventions, resources such as *.properties files can be placed in a src/main/resources directory. The files/folders in this directory will be copied to the root level of the jarW (or other similar package) that is generated for the project. A common use of the resources directory is to place a META-INF directory within the resources directory, and to place files destined for the META-INF directory (within the packaged jar file) within this directory, since they will get packaged into the final jar file.
As an example of this, I have a basic project called "aproject" with a "jar" packaging. I created a resources directory within main. I placed a textfile.txt file within resources. I also created a META-INF directory within resources, and I created a this-goes-in-META-INF.txt file within this directory. If I perform a "mvn clean package" on "aproject", we can see that the contents of the resources directory get copied to the target/classes directory.
If I perform a "jar tf aproject-1.0-SNAPSHOT.jar" to see the contents of the generated jar file, I see the following:
Contents of 'aproject' jar file
META-INF/ META-INF/MANIFEST.MF com/ com/maventest/ com/maventest/App.class META-INF/this-goes-in-META-INF.txt textfile.txt META-INF/maven/ META-INF/maven/com.maventest/ META-INF/maven/com.maventest/aproject/ META-INF/maven/com.maventest/aproject/pom.xml META-INF/maven/com.maventest/aproject/pom.properties
We can see that the contents of the resources directory have been placed in the jar file relative to the root level of the jar file.