简体   繁体   English

Eclipse Build Project和Maven Compile命令之间的区别

[英]Difference between Eclipse Build Project and Maven Compile command

Is Eclipse " Build Project " command same as the Maven command " mvn compile "? EclipseBuild Project ”命令是否与Maven命令“ mvn compile ”相同? Do both basically do the same thing? 两者基本上都做同样的事情吗?

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? 如果 ,那么为什么我在运行“mvn clean install”之后需要在STS中执行“Build Project”才能运行应用程序而没有任何问题? Running "mvn clean install" should have already compiled the project. 运行“mvn clean install”应该已经编译了项目。 Shouldn't Refreshing the project in STS be enough to run it? 不应该刷新STS中的项目足以运行它吗?

If No , then is Eclipse build different because the Java compiler implements the Java Language Specification to build the classes? 如果 ,则Eclipse构建不同,因为Java编译器实现了Java语言规范来构建类吗? But the following Apache Maven link says that the default compiler is javax.tools.JavaCompiler (By the way I am using Java 1.6). 但是下面的Apache Maven链接说默认编译器是javax.tools.JavaCompiler(顺便说一句,我使用的是Java 1.6)。

The short answer is no , maven build and eclipse build are not the same. 简短的回答是 ,maven build和eclipse构建不一样。

Basically, eclipse has its own way of building things, which has little to do with maven. 基本上,eclipse有自己的构建方式,这与maven几乎没有关系。 At the most basic level, Eclipse just does Java compilation, using its own Java compiler (part of Eclipse JDT). 在最基本的层面上,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. M2E尝试使Eclipse IDE的行为“尽可能地模仿”maven的命令行行为。 It does this by configuring your eclipse project. 它通过配置您的eclipse项目来实现。 For example, setting source folders, classpath etc. based on the maven poms. 例如,根据maven poms设置源文件夹,类路径等。 This works pretty well if your poms don't do 'fancy' things (ie use some not so common maven plugins). 如果您的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. 如果你没有插件来“教eclipse”关于你的一些pom的插件。 M2e will give you an error about lifecyle mapping . M2e会给你一个关于生命周期映射错误 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 (eg by installing the corresponding Eclipse 'project configurator'). 这表明m2e和maven命令行可能不会为您的项目“做同样的事情”,并由您决定以某种方式解决它(例如,通过安装相应的Eclipse'项目配置器')。

I don't know Maven but Eclipse build is different from some project's ANT build, so should be the case with Maven. 我不知道Maven,但Eclipse构建与某个项目的ANT构建不同,所以应该是Maven的情况。 Eclipse has its own internal incremental build mechanism. 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. Eclipse内部构建(Eclipse的Build Project或Build All或Clean)和Maven / Ant构建基本上做同样的事情,这意味着它们都将编译源代码文件。 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内部构建不会为您生成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. 关于编译器,当你使用Eclipse构建时,它将使用自己的内部javac编译器与Eclipse打包的Java版本。 You can find Java version using Window's > Preference > Java > Compiler. 您可以使用Window的> Preference> Java> Compiler找到Java版本。 While in case of your own project build, it will refer your JAVA_HOME. 在您自己的项目构建的情况下,它将引用您的JAVA_HOME。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM