Tell Maven to not include src/test/resources in Eclipse


When creating a jar-with-dependencies, the resources in src/test/resources are automatically added to the jar. This folder often contains a .properties file only valid for the test environment and should not be included in the final jar.

Additional Note

Adding a resource tag to exclude the directory is ignored by Maven running in Eclipse. It’s not clear why.


Right-click the source folder “src/test/resources” and click “Build Path|Configure Exclusion/Inclusion Filters…”. Add an exclusion filter of **. Now the resources will not be included in the final jar file.

Testing from Eclipse

When running from eclipse, it is possible to include the content of src/test/resources in the classpath. Here’s how:

  1. Right-click src/main/java
  2. Click “Properties”
  3. Click “Run/Debug Settings”
  4. Select a Launch Configuration you want to change.
  5. Click Edit.
  6. Click the Classpath tab.
  7. Click Advanced…
  8. Click Add Folders and Click Ok
  9. Select the src/test/resources folder on your project.

Now when running from eclipse, the test resources are in the classpath. It maybe necessary to make this change for several launch configurations.


168 Words

2011-05-03 13:13 +0000