mvn eclipse:eclipse versus regular maven build - eclipse

What is the difference between running a maven build on a maven project
mvn install
then importing the module in eclipse (Import > Existing Maven Projects) as a maven artifact versus running
mvn install eclipse:eclipse
and importing the maven project as a regular project (Import > Existing Projects into Workspace)?
The second option seems faster within eclipse (mvn install eclipse:eclipse) but I'm not sure why.

When you import an existing Maven project, it is done by m2e, the official Eclipse Maven plugin (when I say official I mean it is in the Eclipse incubation process). It offers more features and can be more convenient to use in my experience
When you do it by eclipse:eclipse, it is done by a Maven Eclipse mojo which creates a simple Java project. The problem is that you have to re-do this again every time you change your pom.xml. With m2e, this is usually done automatically.

Related

add a specific jar from maven repository

In Eclipse i forgot how to add a specific jar from m2 repo in the case that we have a maven project without the m2e Plugin in Eclipse
From the command line, run mvn eclipse:eclipse to generate Eclipse metadata for your project, then restart Eclipse and, if needed, reimport your projects.
You'll need to repeat that for every dependency change. In the long run, you're probably better off using m2e.

How to script maven commands in Eclipse

I have a maven project in Eclipse with a bunch of local project dependencies.
Building with the Maven assembly plugin or shade plugin is a pain because I first have to build and install all of the local project dependencies before I can build my main project.
Does m2e provide a way to script a sequence of arbitrary maven commands? I know I can script everything from the command line, I just don't know where m2e's instance of maven is installed, and I'd like to avoid installing a separate instance.
Have you considered creating a multi-module Maven project that "contains" the dependencies? That would allow you to build just the container and Maven automatically takes care of building the component modules. Eclipse's m2e supports multi-module builds so there wouldn't be anything special to do for Eclipse.

How is the maven build different from eclipse build?

I have integrated m2e plugin.When i change the java file .It invokes building workspace. Is this is eclipse build or maven build.
And what exactly the difference between Eclipse clean and mvn clean ?
The m2e plugin injects the Maven classpath into the Eclipse project plus it disables the default Eclipse resource copying so Maven can do it's magic (the Maven resource copy step can filter/transform resources).
The actual build for Java files uses the Eclipse compiler with the classpath supplied from m2e.
Clean: Unless you have configured something special, Eclipse clean will delete target/classes and target/test-classes while mvn clean will delete the whole target/ folder.
Also, Eclipse will build the project again right after clean. For Maven, you need to issue another command (mvn compile or mvn install).
Check your .project file.
Do you have something like org.eclipse.m2e.core.maven2Builder there? Then it's Maven build executed by Eclipse via m2e.
The exact difference between "Eclipse clean" and mvn clean...
mvn clean executes Maven clean phase, as it is configured (or inherited) in the pom.xml.
For Eclipse clean, see this question:
Function of Project > Clean in Eclipse

How to add Maven dependencies in Eclipse libaries

Can any one explain how to add Maven dependency JAR i.e. build path libraries? To be very specific how to include JAR file mentioned in pom.xml to Java build path? Maven dependencies - unable to see jars over here.
Don't have a option to update Maven dependencies. Also executed the script mvn eclipse:eclipse, seen on StackOverflow.
Generally, you should not have any need to deal with such a task manually. Here is the correct procedure for importing of maven project to your Eclipse IDE:
Make sure you have m2eclipse plugin installed (Maven support for Eclipse). As far I remember it is included to Eclipse IDE for JEE developers by default.
Checkout your maven project to any directory
From this directory (root pom.xml is located in), run: mvn eclipse:eclipse
Go to Eclipse, File -> Import, select "Existing maven project"
Select directory where your root pom.xml is located, Eclipse should find all maven modules.
Optional: if eclipse will tell you that it can't recognize some maven plugins - ignore this, just continue.
If you follow this instruction, IDE will create all maven modules as eclipse projects and you will have an option to update maven dependencies and also willsee all of them rigth in IDE.

Trying to understand how to work with Maven and Eclipse

I import a project into eclipse from svn and then go and run 'mvn install' from the command line and everything compiles fine. But I don't understand why the code is not compiled in Eclipse too.
From my previous experience I know that I need to go ahead in Eclipse and import "existing maven projects" to have Eclipse compile the code, I just don't understand why.
Thanks!
How have you imported the projects to Eclipse? By runnint mvn eclipse:eclipse to import them as 'Java project' or importing the maven projects directly with the m2eclipse plugin?
By default maven builds each project into a directory target in each project whereas Eclipse builds into eclipse-out. mvn install builds each maven project to create an archive (jar, war, ear etc) whereas Eclipse needs to build to be able to run the code in Eclipse.