Usually when you create any new Maven project, the src/main/java, src/test/java, src/main/resources, src/test/resources directories will be the default source and resources directory of the project.
If you want to add a new source or resource directory from a directory in this project, for example, the db directory in my example above:
then you can right-click on the project and select Build Path and then select Configure Build Path … Then in the Source tab, click Add Folder … then check the db folder:
to include this directory as the project’s source folder.
But here our project is Maven project, when committing code for others to use, usually, we will not commit the .classpath file of Eclipse project. Therefore, if you do this, when others import and build your project with Maven, this configuration will be lost. To configure this folder is always the resource folder of Maven project, please open the Maven pom.xml file, declare using the build-helper-maven-plugin plugin with the goal add-resource for the db directory as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <id>add-resource</id> <phase>generate-resources</phase> <goals> <goal>add-resource</goal> </goals> <configuration> <resources> <resource> <directory>src/main/db/</directory> </resource> </resources> </configuration> </execution> </executions> </plugin> |
Result:
To configure this folder is Maven project’s source folder, you declare as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>src/main/db/</source> </sources> </configuration> </execution> </executions> </plugin> |
Result:
It’s convenient, isn’t it?