Search code examples
eclipsemaven

How to resolve errors due to duplicate java files in Eclipse project ? The type 'xxx.java' already defined error


I was having a perfectly working project in Eclipse IDE for Enterprise Java and Web Developers Version: 2023-12 (4.30.0) Build id: 20231201-2043

Suddenly, when I login to the Remote Desktop where my Eclipse was installed, in the package explorer as well as in project explorer, I started seeing an error reported that certain java file is 'present already'. I see the below project structure as shown.

I tried project-->refresh/clean, maven clean etc. for no help

BTW, when I run the 'maven test' it runs despite the display of the error. It is also building fine also.

I saw similar issues reported in SO already, but could not resolve. enter image description here ANSWER:(Found via @nitind comment) The folder structure under src/main/java is shown. Based on @nitind comments, I discovered this. It appears I am blind and as well as dumb. Lol ! Thanks to the extra pair of intelligent eyes.

enter image description here


Solution

  • @nitind Bro ! It appears I am blind and as well as dumb. I am migrating test classes that were kept under src/main/java on to src/test/java. I observed that I have left the AndroidTestBSVenkata.java still under src/main/java which might be the reason. Probably I should be removing it. I updated the main question with the new pic snippet.

    Yes, I confirm that once I renamed the file under src/main/java from AndroidTestBSVenkata.java to AndroidTestBSVenkataTBD.java, the error went away. Obviously.

    Your comment prompted me to the right answer.