Eclipse Build Project 和 Maven Compile 命令的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30257748/
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 22:37:59  来源:igfitidea点击:

Difference between Eclipse Build Project and Maven Compile command

javaeclipsemavenbuildsts-springsourcetoolsuite

提问by Arthas

Is Eclipse"Build Project" command same as the Mavencommand "mvn compile"? Do both basically do the same thing?

Eclipse的生成项目”命令相同的Maven命令“ MVN编译”?两者基本上都做同样的事情吗?

If Yes, then why do I need to do a "Build Project" in STS after running "mvn clean install" in order to run the application without any issues? Running "mvn clean install" should have already compiled the project. Shouldn't Refreshing the project in STS be enough to run it?

如果,那么为什么我需要在运行“mvn clean install”后在 STS 中执行“构建项目”才能运行应用程序而没有任何问题?运行“mvn clean install”应该已经编译了项目。在 STS 中刷新项目不应该足以运行它吗?

If No, then is Eclipse build different because the Java compiler implements the Java Language Specification to build the classes? But the following Apache Maven linksays that the default compiler is javax.tools.JavaCompiler (By the way I am using Java 1.6).

如果,那么 Eclipse 构建是否不同,因为 Java 编译器实现了 Java 语言规范来构建类?但是下面的Apache Maven 链接说默认编译器是 javax.tools.JavaCompiler(顺便说一下,我使用的是 Java 1.6)。

回答by Kris

The short answer is no, maven build and eclipse build are not the same.

简短的回答是否定的,maven build 和 eclipse build 不一样。

Basically, eclipse has its own way of building things, which has little to do with maven. At the most basic level, Eclipse just does Java compilation, using its own Java compiler (part of Eclipse JDT).

基本上,eclipse有自己的构建方式,这与maven关系不大。在最基本的层面上,Eclipse 只是使用自己的 Java 编译器(Eclipse JDT 的一部分)进行 Java 编译。

A precise answer to how they differ is hard to give, the situation is quite complex, and it depends precisely on what stuff (Eclipse plugins) you have installed.

很难给出它们有何不同的准确答案,情况非常复杂,这完全取决于您安装了哪些东西(Eclipse 插件)。

To get an as close as possible approximation so that what Eclipse does, resembles most to what maven does on the commandline you should install m2e (maven eclipse tooling).

为了获得尽可能接近的近似值,以便 Eclipse 所做的与 maven 在命令行上所做的最相似,您应该安装 m2e(maven eclipse 工具)。

M2E tries to make your Eclipse IDE's behavior 'emulate' as closely as possible to maven's commandline behavior. It does this by configuring your eclipse project. For example, setting source folders, classpath etc. based on the maven poms. This works pretty well if your poms don't do 'fancy' things (i.e. use some not so common maven plugins).

M2E 尝试使您的 Eclipse IDE 的行为“模拟”尽可能接近 maven 的命令行行为。它通过配置您的 eclipse 项目来做到这一点。例如,基于 maven poms 设置源文件夹、类路径等。如果你的 poms 不做“花哨的”事情(即使用一些不那么常见的 maven 插件),这很有效。

When you do use maven plugins in your pom to do 'special' things like maybe generate some code, or whatever, then m2e has a plugin mechanism that allows maven plugin authors to define a corresponding eclipse plugin which 'teaches eclipse' how to do the same thing.

当你在你的 pom 中使用 maven 插件来做“特殊”的事情时,比如可能会生成一些代码,或者其他什么,那么 m2e 有一个插件机制,允许 maven 插件作者定义一个相应的 eclipse 插件,它“教 eclipse”如何做一样。

This can get hairy, because not all maven plugins have corresponding Eclipse plugins, and even if they do, they are not automatically installed for you into your instance of Eclipse.

这可能会很麻烦,因为并非所有 maven 插件都有相应的 Eclipse 插件,即使有,它们也不会自动为您安装到您的 Eclipse 实例中。

If you haven't got the plugins to 'teach eclipse' about some of your pom's plugin. M2e will give you an error about lifecyle mapping. This is an indication that m2e and maven commandline may not 'do the same thing' for your project, and its up to you to resolve it somehow (e.g by installing the corresponding Eclipse 'project configurator').

如果你还没有插件来“教 Eclipse”你的一些 pom 插件。M2e 会给你一个关于生命周期映射错误。这表明 m2e 和 maven 命令行可能不会为您的项目“做同样的事情”,由您决定以某种方式解决它(例如,通过安装相应的 Eclipse“项目配置器”)。

回答by hagrawal

I don't know Maven but Eclipse build is different from some project's ANT build, so should be the case with Maven. Eclipse has its own internal incremental build mechanism.

我不知道 Maven,但 Eclipse 构建与某些项目的 ANT 构建不同,因此 Maven 应该是这种情况。Eclipse 有自己的内部增量构建机制。

Eclipse internal build (Eclipse's Build Project or Build All or Clean) and Maven/Ant build basically do the same thing which means that they both will compile the source code file. Now an obvious difference is that Eclipse internal build will not generate EAR, WAR etc. files for you, which you do using ANT/Maven.

Eclipse 内部构建(Eclipse 的 Build Project 或 Build All 或 Clean)和 Maven/Ant 构建基本上做同样的事情,这意味着它们都将编译源代码文件。现在一个明显的区别是 Eclipse 内部构建不会为您生成 EAR、WAR 等文件,而您使用 ANT/Maven 执行这些文件。

If ANT/Maven you specify you class-path using there respective elements, and same think is done in Eclipse by configuring build path, so that when Eclipse does internal build, then those JAR or runtime libraries can be referenced.

如果 ANT/Maven 您使用各自的元素指定类路径,并且通过配置构建路径在 Eclipse 中完成相同的想法,以便当 Eclipse 进行内部构建时,可以引用那些 JAR 或运行时库。

Regarding compiler, when you build using Eclipse then it will use its own internal javac compiler of the Java version Eclipse is packaged with. You can find Java version using Window's > Preference > Java > Compiler.While in case of your own project build, it will refer your JAVA_HOME.

关于编译器,当您使用 Eclipse 构建时,它将使用它自己的内部 javac 编译器,该编译器是与 Eclipse 打包在一起的 Java 版本。您可以使用 Window's > Preference > Java > Compiler 找到 Java 版本。而在您自己的项目构建的情况下,它将引用您的 JAVA_HOME。