Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Clean, Update, Install and Eclipse Clean, Refresh, Build -- a generally correct order?

I have a few interdependent Eclipse projects. When I am trying to build my workspace, I am running into multiple issues. Supposedly, the issues should go if I do Maven clean, update, install, and Project clean, refresh, build all (I am doing everything in Eclipse through Run and Project menus correspondingly).

However, I am confused what should be the best order to perform these actions? Also, can anybody briefly explain what each of them does so I could get better understanding and make sense when I can skip some?

More specifically: I was told that running Maven Clean & Maven Install would suffice. Although Maven Install ends in 'Build Success', I still have errors on the Problems tab and a nasty error "Could not find or load main class export" when trying to run some classes in a particular project. I try running Project Clean couple times and then Project Build another couple times, and the errors might or might no go. I was advised to introduce Maven Update -> all projects and select all projects > Refresh (F5) steps, but I am not sure when to perform them (after what clean or install or build).

Is there any 'generally correct' order of how to perform these actions? So that if I perform it and some errors stay, it will become clear that something is wrong within my version rather than simply with the dependencies? I have pulled the projects from RTC (a software development team collaboration tool) and my colleagues do not have those problems. However, I just pulled it recently.

like image 602
alisa Avatar asked Jan 22 '16 02:01

alisa


2 Answers

First, you have to understand that maven and eclipse are two different things. Yes, there is the m2e plugin (that now comes bundled in eclipse) that does a very good job in configuring eclipse projects based on maven projects. But, sometimes eclipse gets messed up (almost always because of refresh problems).

Second, you may have to learn about Maven Build Lifecycle Basics:

There are three built-in build lifecycles: default, clean and site. The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project's site documentation.

So, basically:

  • clean is a phase of the clean lifecycle, deletes your target directory
  • install is a phase of the default lifecycle, does a lot of things because triggers all the previous phases (generates sources, compiles, run tests, etc, and ends up putting your packages in your target directory and putting the artifacts in the local repository.

Third, about eclipse. You don't have to run Build if you have checked the "Project -> Build Automatically" option. When eclipse gets messed up, I found that executing the m2e command "Maven -> Update project" and then a Refresh, it's enough. This command regenerates some files in the .settings folder. In some rare cases, I have had to remove all the files in the .settings folder by myself, and then run the "Update Project" command.

Conclusion: mvn clean install should do the job, if not eclipse -> Refresh, if still not working eclipse - > Maven -> Update Project

I also recommend using the last version of eclipse and m2e plugin.

like image 107
Pablo Lascano Avatar answered Nov 15 '22 03:11

Pablo Lascano


Specifically in my case, the following sequence of actions worked:

  • Project -> uncheck Build Automatically
  • [accept incoming changes] if applies
  • Project -> clean
  • Run -> Run As -> Maven clean
  • Run -> Run As -> Maven install
  • Project -> check build automatically
  • if errors on Problems Tab appear:
    • select all projects, Refresh F5
    • if still errors:
      • delete errors manually on Problems Tab (it might be that Eclipse has not updated the dependencies, etc.)
      • select all projects, Refresh F5
like image 45
alisa Avatar answered Nov 15 '22 05:11

alisa