Difference between Eclipse Build Project and Maven Compile command
Asked Answered
S

2

19

Is Eclipse "Build Project" command same as the Maven command "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? Running "mvn clean install" should have already compiled the project. Shouldn't Refreshing the project in STS be enough to run it?

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 link says that the default compiler is javax.tools.JavaCompiler (By the way I am using Java 1.6).

Sunday answered 15/5, 2015 at 10:55 Comment(0)
F
20

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

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

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.

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

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

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.

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.

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

Fuss answered 15/5, 2015 at 16:36 Comment(2)
Is this better under IntelliJ? I have a feeeling I never had a problem there.Snatch
I am not really an IntelliJ user, so I may be wrong. But I think is better in the sense that IntelliJ doesn't actually build your project while you type. So it won't show errors for things you don't open. Which means it won't show bogus errors most of the time. The flip side of this is that it also won't show genuine errors in some source file until you actually open it, or until you run a manual build of your code somehow. So it's both better and worse at the same time.Fuss
P
1

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.

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.

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.

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.

Polad answered 15/5, 2015 at 13:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.