Search code examples
javaeclipsemavenpackagem2eclipse

m2e plugin - Eclipse - created Java class and package. Not recognized as part of the project


I installed m2e (1.7) plugin to use maven on eclipse Mars. Creating a new maven web-app project, I tried to add a new java class to src/main/resources folder. I simply created an Hello.java class in com.sample package.

As you can see from the image below, the package is not shown as package visualization (It is shown as a folder path to the java class) and most important, opening the Hello.java class, editing the file with error, eclipse does not point out the error. Even the Hello.java file icon is different.

How I can fix the problem? thank you in advance.

m2e eclipse project


Solution

  • Normally, the Java source code should be in src/main/java source folder, not in src/main/resources like yours. To fix this: You should check if the src/main/java existed or not. You can do this by expanding the src/main folder at the bottom of the above image.

    If there is a java folder, you select and right click on the java folder --> Build Path --> Use as Source Folder.

    If there is no src/main/java, you can create new one by right click on your project --> New --> Source Folder. Enter src/main/java

    Then move your Hello.java to that folder.