2

I am using Maven projects in my Eclipse workspace. But, somehow Eclipse is referring the old .class files while running the program. Hence, I have to re-build the complete project everytime I make any change to any java program.

I have tried executing maven commands like eclipse:clean & eclipse:eclipse. But, they did not help. My eclipse is also set to project - build automatically.

Is there a way I can tell Eclipse to refer to the current built .class files and not the previously built maven .class files.

Note: I am using Eclipse Mars Thanks in advance.

greg-449
  • 109,219
  • 232
  • 102
  • 145
AnirbanDebnath
  • 990
  • 16
  • 26
  • Clean isn't removing all old class files? – ChiefTwoPencils Apr 28 '16 at 05:16
  • Thing is, I have `build automatically` enabled, but when I select `Build Project / build all projects` Eclipse is not building any project. Only when I do a `Maven` build, it rebuilds the complete project. – AnirbanDebnath Apr 28 '16 at 05:38
  • Due to this, if I do a `eclipse clean project`, and then try to run the project, I get a `Could not find or load main class` Error. – AnirbanDebnath Apr 28 '16 at 05:39
  • Are you using M2Eclipse? – Peter Apr 28 '16 at 08:58
  • @Peter: No, I am using Eclipse Mars, and Maven is already integrated into Mars by default. Is M2Eclipse a different version ? And how is going to be helpful? – AnirbanDebnath Apr 28 '16 at 11:42
  • M2Eclipse or m2e is the maven plugin for eclipse, but it seems to be delivered with nearly every eclipse distribution. Could you explain your project setup in more detail? Do you have a single module? What do you mean by old `.class` files? Does eclipse build into a different directory than maven does? What kind of changes to the java program causes the issue? – Peter Apr 28 '16 at 14:11
  • @Peter: There are several modules which are interdependent on each other. 1) By old `.class` files I mean class files created by maven; since my `auto build` in eclipse is not working on maven projects. `--->` If I perform `eclipse clean build on the project` the `.class` files are deleted but not generated again when i do `eclipse build / build all`. Only when I perform `maven clean install`; thats when those `.class` files are re-created. 2) The directory of the `.class` files are the same for both maven as well as eclipse. 3) Any type of changes. e.g. writing a printf stmnt. – AnirbanDebnath Apr 28 '16 at 15:21
  • @AnirbanDebnath Did you find solution for this? I'm also having same issue. – Syed Mohammed Mehdi Aug 15 '20 at 10:21
  • @SyedMohammedMehdi: Sometimes the .project file of Eclipse gets corrupted. Easy solution is : 1. Delete the project from Eclipse. 2. Close Eclipse. 3. Go to your project's folder and delete ".settings, .project, .classpath, bin" 4. Open Eclipse again, and import your project once again. This way it always works. – AnirbanDebnath Aug 24 '20 at 08:37

2 Answers2

0

I am afraid. There is no way to doing it automatically. Even if you find a way to do so. There isn't any guarantee that eclipse will build with new war.

Either you go for manual mvn clean install or use intellij idea it is very much statble. No build issue. Every time on your single save it will build new war file.

Harshil
  • 69
  • 1
  • 2
0

Posting answer to my question:

Sometimes the .project file of Eclipse gets corrupted. Easy solution is :

  1. Delete the project from Eclipse.
  2. Close Eclipse.
  3. Go to your project's folder and delete ".settings, .project, .classpath, bin"
  4. Open Eclipse again, and import your project once again.

This way it always works.

AnirbanDebnath
  • 990
  • 16
  • 26