Resource from Src/Main/Resources Not Found After Building With Maven

Maven Compile cant find src/main/resources directory

The filter (link) element will parse your files and apply a content filter on them.
The profiles (link) element helps you define different environments for the build.

All of this as to do with your resources. These can be configuration files, or other type of files. If you filter then you can change the content of this files with other values - e.g. pom properties. When using profiles you can have different replacement properties for each environment.

You should move the profiles up in the tree for the default path, or add a configuration in your pom for the resource location.
The base dir is the folder containing your pom. You should have your profile folder here.

My own example

Also, here is some good information about profiles and its configurations.

Eclipse doesn't show src/main/resources in my maven project the way I see it elsewhere

You need to add the resources folder to your classpath. Please do the following

  1. Right click the folder
  2. Hover over Build Path
  3. Click Use as Source Folder

Java Sample Image 1

Those top level directories are source folder "short cuts"

Why is Maven not including my file /src/main/resources/config.props?

The root of your WAR file is not resources, but rather src/main/webapp. If you want files directly under WEB-INF in your WAR file, put them in src/main/webapp/WEB-INF. Resources under src/main/resources will end up under /WEB-INF/classes in your WAR file.

For example, if your source looks like this:

|____ src
| |____ main
| | |____ resources
| | | |____ config.props
| | |____ webapp
| | | |____ WEB-INF
| | | | |_____ web.xml
| | | |____ index.jsp

Your WAR file will look like this:

|____ WEB-INF
| |____ classes
| | |____ config.props
| |____ web.xml
|____ index.jsp

Exclude files from src/main/java and src/main/resources spring boot jar

I found solution, as following; it is using the maven jar plugin exclusions. There were issues in maven wildcard which was provided earlier.

Edit: Not the right approach to include java files which are removed while buliding artifact as suggested by JF Meier and khmarbaise. But solution is still valid for files exclusion.


Maven default Resources not copying resources

Found the answer. The default behaviour of the maven-resources-plugin is to package the resources inside the jar. If you open the jar with a zip program you will see the resources inside it. To change the behaviour of the default resources plugin (maven-resources-plugin ) in the default phase (process-resources) with the default goal (resources) you must use the tag <resources> as child of <build>:

EDIT: the default behaviour of the maven-resources-plugin is to package the resources inside the jar alongside the target/classes folder.


In this way resources will go outside the jar in the specified folder. If you want to send some resources in the jar and some outside:

<include>this_file_will_go_outside_the_ jar_in_the_folder.txt</include>
<!-- without targetPath everything not excluded will be packaged inside the jar -->
<exclude>this_file_will_go_outside_the_ jar_in_the_folder.txt</exclude>

EDIT: note that with the first option resources will still be copied into the target/classes folder (and in the jar/artifact). Excluded resources will not be present in the classpath so you will not be able to access them by running the code from Eclipse. You will only be able to access them from an executable jar with the targetPath folder specified as classpath in the manifest file. A better option is to confure the mave-jar-plugin and the maven-resources-plugin. See this and this answer.

Related Topics

Leave a reply