Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Eclipse Build Project and Maven Compile command

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

like image 643
Arthas Avatar asked May 15 '15 10:05

Arthas


People also ask

What is Maven compile command?

mvn compile: Compiles source code of the project. mvn test-compile: Compiles the test source code. mvn test: Runs tests for the project. mvn package: Creates JAR or WAR file for the project to convert it into a distributable format. mvn install: Deploys the packaged JAR/ WAR file to the local repository.

How do I compile and run a Maven project in Eclipse?

Building and Running the Maven Project in Eclipse To run the maven project, select it and go to “Run As > Java Application”. In the next window, select the main class to execute. In this case, select the App class and click on the Ok button. You will see the “Hello World” output in the Console window.

What does Maven build do in Eclipse?

Using Maven with the Eclipse IDE The Eclipse IDE provides support for the Maven build. This support is developed in the M2Eclipse project. It provides an editor for modifying the pom file and downloads dependencies if required. It also manages the classpath of the projects in the IDE.

What is Eclipse build?

What is an Eclipse Source Build? Eclipse source builds provide developers with an automated method for checking out source code and other required resources, compiling the Java code, generating javadoc, and finally, copying launcher files to the right location to launch Eclipse.


1 Answers

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

like image 85
Kris Avatar answered Sep 19 '22 13:09

Kris