Maven Clean、Update、Install 和 Eclipse Clean、Refresh、Build——一个通常正确的顺序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34938056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:01:49  来源:igfitidea点击:

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

javaeclipsemavenbuildrtc

提问by alisa

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).

我有几个相互依赖的 Eclipse 项目。当我尝试构建我的工作区时,我遇到了多个问题。据说,如果我执行 Maven 清理、更新、安装和项目清理、刷新、构建所有操作(我通过相应的运行和项目菜单在 Eclipse 中执行所有操作),问题应该会消失。

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).

更具体地说:有人告诉我,运行 Maven Clean & Maven Install 就足够了。尽管 Maven 安装以“构建成功”结束,但在尝试运行特定项目中的某些类时,我仍然在“问题”选项卡上出现错误和“无法找到或加载主类导出”的严重错误。我尝试运行 Project Clean 几次,然后再运行 Project Build 几次,错误可能会也可能不会发生。有人建议我引入 Maven 更新 -> 所有项目并选择所有项目 > 刷新 (F5) 步骤,但我不确定何时执行它们(在清理或安装或构建之后)。

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.

如何执行这些操作是否有任何“总体正确”的顺序?因此,如果我执行它并且一些错误仍然存​​在,很明显我的版本中有问题而不是简单的依赖关系?我已经从 RTC(一种软件开发团队协作工具)中提取了项目,我的同事没有这些问题。但是,我最近才拔了它。

采纳答案by alisa

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
  • 项目 -> 取消选中自动构建
  • [接受传入的更改] 如果适用
  • 项目 -> 清洁
  • 运行 -> 运行方式 -> Maven clean
  • 运行 -> 运行方式 -> Maven 安装
  • 项目 -> 自动检查构建
  • 如果问题选项卡上出现错误:
    • 选择所有项目,刷新 F5
    • 如果仍然错误:
      • 在问题选项卡上手动删除错误(可能是 Eclipse 尚未更新依赖项等)
      • 选择所有项目,刷新 F5

回答by Pablo Lascano

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).

首先,你必须明白maven和eclipse是两个不同的东西。是的,有 m2e 插件(现在捆绑在 eclipse 中)在基于 maven 项目配置 eclipse 项目方面做得非常好。但是,有时 eclipse 会搞砸(几乎总是因为刷新问题)。

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

其次,您可能需要了解Maven 构建生命周期基础知识

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.

有三个内置的构建生命周期:default、clean 和 site。默认生命周期处理您的项目部署,clean 生命周期处理项目清理,而站点生命周期处理项目站点文档的创建。

So, basically:

所以,基本上:

  • cleanis a phase of the clean lifecycle, deletes your target directory
  • installis 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.
  • clean是 clean 生命周期的一个阶段,删除您的目标目录
  • install是默认生命周期的一个阶段,做了很多事情,因为触发了之前的所有阶段(生成源、编译、运行测试等,最后将你的包放在你的目标目录中,并将工件放在本地存储库中。

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.

三、关于日食。如果您已选中“项目 -> 自动构建”选项,则不必运行构建。当eclipse搞砸时,我发现执行m2e命令“ Maven -> Update project”然后刷新,就足够了。此命令会重新生成 .settings 文件夹中的一些文件。在极少数情况下,我不得不自己删除 .settings 文件夹中的所有文件,然后运行“更新项目”命令。

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

结论:mvn clean install应该完成这项工作,如果不是eclipse -> Refresh,如果仍然不工作eclipse -> Maven -> Update Project

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

我还建议使用最新版本的 eclipse 和 m2e 插件。

回答by J?rg

A best practice from devonfw.com is to separate and decouple command-line maven and eclipse build. This saved my life. The magic trick is simple and can be found here: https://github.com/devonfw/devon4j/blob/develop/pom.xml#L544

devonfw.com 的最佳实践是将命令行 maven 和 eclipse 构建分离和解耦。这救了我的命。魔术很简单,可以在这里找到:https: //github.com/devonfw/devon4j/blob/develop/pom.xml#L544

BTW: devonfw has tons of great patterns to learn from. This is just one out of a million.

顺便说一句:devonfw 有很多很棒的模式可供学习。这只是百万分之一。