hc0re
hc0re

Reputation: 1986

Maven project problem - wrong package namespaces?

I have to modify something in an very old project, It is basically a maven project. When I import it as "Existing maven project" in Eclipse, the Java imports (internal imports) in java classes are burning red.

For example:

com.company.app.server.biz.exception;

Is underscored red and Eclipse says:

Declared package "com.company.app.server.biz.exception" does not match the expected package "main.java.com.company.app.server.biz.exception"

It is also missing some other imports, like something from apache.commons but it is easily fixed using "Fix project setup". The "Fix project setup" is not doing anything when trying to fix the internal project classes problems.

Am I doing something wrong here? What can be wrong?

Upvotes: 1

Views: 1470

Answers (2)

PTN
PTN

Reputation: 1

I know it's an old question/answer, but I just imported an existing Maven project and got exactly the same error.

So, if anyone else also finds this question, to solve it I simply deleted the project project in eclipse (but not the contents on disk) and re-imported it. Now it works fine.

Upvotes: 0

kapex
kapex

Reputation: 29999

Eclipse by default expects that /src/ is your source folder. Maven usually has all Java sources in /src/main/java/.

Seeing main.java. before expected package names indicates that your source folders aren't set up correctly. Eclipse incorrectly sees these folders as part of your package structure.

You either need to manually set up /src/main/java/ as a source folder in the project's build path menu or you can try to use the "Maven -> Update project" feature from the project's context menu.

Upvotes: 1

Related Questions