How to Fix missing src/main/java & src/test/java folders in the Eclipse Maven web Project?

By | November 4, 2020

In this post, We will learn How to Fix missing src/main/java & src/test/java folders in the Eclipse Maven web Project?

How to fixing src/main/java and src/test/java folders in Eclipse Maven Project – 2 build path entries are missing:

Sometimes, when you create a maven web application project, you will not see src/main/java and src/test/java as a source folder. When you try to create it manually you will get an error like “The folder is already a source folder”. In this tutorial, let’s see how to fix the missing src/main/java folder in the Eclipse Maven project

Step 1: Open the Eclipse and Go to File -> New -> Others.

Step 2: In the opened New wizard, scroll down and select Maven->Maven Project, click Next

3: In the below screen, If you do not want to create your maven project on the default Workspace location then Uncheck the “Use default Workspace location” checkbox option and with the help of the Browse button choose your workspace where you would want to create your Maven project. Click on Next.

4: Just scroll down and select option with Artifact Id as maven-archetype-webapp and Click on Next

5: Now You have to provide Group Id, Artifact Id & version. These attributes basically give your project deliverable(jar/war/ear etc.. ) a unique identity in the repository. Click Finish

Step 3: After you create a maven web application, you will see the Web project created like below. Now we can that the SampleWebApp Project doesn’t have src/main/java and src/test/java folders in it. It has only the src/main/resource folder.

Step 4: Even when We try to create a new Source folder We will an error like ” The Folder is already a source folder “.

Right-click on  your project then go to Source Folder and try to create src/main/java then it will show an error that is depicted in the below screen shots

Step 5: Fixing this issue is really very simple, Just Right Click on the project go to Properties. After that go to Build Path, You see an error like ” 2 build path entries are missing “

Step 6: This error usually comes when the JRE System Library is wrongly pointed. Now go to the Libraries tab and change the JRE System Library to the correct version by clicking on Edit.

Note: In case if you do not see the src/main/java and src/test/java directories in your project structure then you will have to go to Project ->Properties ->Java BuildPath ->Libraries after that select JRE System Library and click on Edit and Select or configure correct JRE System Library click on Finish and then click on Apply. You should see those( src/main/java and src/test/java) folders/directories now. You may also right-click on your project then maven -> Update Project->Ok to perform a maven-update on your project.

Note: You should keep in mind that in recent Eclipse versions you don’t need to use mvn eclise:eclipse anymore because this functionality is now built-in with the recent m2e eclipse plugin

Step 7: Once the JRE System Library is changed/updated the issue should be resolved, You may also do Maven Update Project (Right on the Project –> Maven –> Update Project). Now you must have the src/main/java and src/test/java folders in your project.

That’s Yet!!

That’s all about How to Fix missing src/main/java & src/test/java folders in the Eclipse Maven web Project?
If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *