Add new source or resource directory to Maven project using Builder Helper Maven Plugin

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.

Add new source or resource directory to Maven project using Builder Helper Maven Plugin

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:

Add new source or resource directory to Maven project using Builder Helper Maven Plugin

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:

Add new source or resource directory to Maven project using Builder Helper Maven Plugin

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:

Result:

Add new source or resource directory to Maven project using Builder Helper Maven Plugin

To configure this folder is Maven project’s source folder, you declare as follows:

Result:

Add new source or resource directory to Maven project using Builder Helper Maven Plugin

It’s convenient, isn’t it?

Add Comment