Lukasz Lukasz - 4 months ago 31
Java Question

Wrong package name when using automatically added imports in Eclipse

I have several Maven projects converted into one Eclipse workspace. When I edit the code under Eclipse, I sometimes use CTRL+SHIFT+M combination of keys to automatically add imports to the classes from a project in my workspace. But somehow they are added like this:

import src.main.java.com.mycompany;


while to real package I wanted to import is
com.mycompany
.
This has to be some configuration in Eclipse to fix this but I'm confused. However, this issue is very annoying.

EDIT:

I've forgotten to mention that Eclipse files were generated using
mvn eclipse:eclipse
command.

Under Eclipse project seems to be configured properly. Its source folders set like this:


  • src/test/java

  • src/test/resources

  • src/main/java

  • src/main/resources



And everything under Eclipse works properly except the situation when I press CTRL+SHIFT+M keys

Answer

The standard source folder for Java projects is

./src

For imported maven projects, simply remove this folder from the list of source folders at the build path settigs. The correct source folder is

./src/main/java
Comments