Maven project JARs weirdly structured - java

I am using Maven m2e as my Eclipse project.
My Maven project was acting weird so I right clicked my pom.xml and went to run as -> maven build then under goals I first did eclipse:clean and then eclipse:eclipse. Before I did that all my JARs were inside the Maven Dependencies folder. Now most of my jars are located in my project folder, outside the maven dependencies folder. Why is that? And how can I revert those changes?
This is how it looks now:

mvn eclipse:eclipse is a relic from ancient times, don't use it.
Basically, what it does is taking the information from a pom.xml and using it to create a native Eclipse project. That was a nice approach 5 years ago, when Eclipse didn't understand Maven projects, but ever since m2eclipse / m2e were introduced, this approach was deprecated in favor of these plugins that actually try to understand the pom.xml.

Related

Organize Maven Dependency in eclipse

I know how to add maven dependencies in eclipse. But I am looking for organizing them.
After issuing
eclipse:eclipse
and importing the project in the eclipse, all the dependency library appears.
Now from what i have experience all the dependent jar were all under the "Maven Dependencies". But i see all the jar are loose - just under the project name.
Basically what i am interested is from
to this :
Rather than using mvn eclipse:eclipse and importing as existing project, got to
File-> Import-> Maven-> Existing Maven Projects
and select your project from there. If you do it that way, your maven dependencies should come up under Maven Dependencies section.

Eclipse Maven Export Missing

I'm using Eclipse Kepler 64 bit. It already has m2e (maven plugin) pre-installed by default.
The import wizard has a Maven option but the export one doesn't:
I tried installing m2e from the Marketplace but it said that there was nothing to install.
How do I get it as export option as well?
As far as the M2E plugin is concerned, using Maven with Eclipse involve importing existing project, and making sure the pom.xml is complete (with the right "nature" added in it, in order to generate the right .project, as in this example)
See "Importing Maven Projects" in the Sonatype book.
But once the project is imported, it becomes a regular project (with additional maven capabilities), without any maven-specific export options.
All you need to "export" a maven project are the sources and the pom.xml: anyone can then run maven to get all the dependencies (from the pom.xml specifications).

How to quickly replace a Maven Dependency with an Eclipse project?

I have setup a Dynamic Web Project in Eclipse using Maven. The Web Project has a lot of dependencies to other JARs. The JARs are properly added to the WEB-INF/lib folder in Maven/Eclipse. Many of the JARs though are results of other plain Java projects. I want to have the JARs represented by their resepective Java projects in Eclipse from time to time (but not for all of them).
So how do I quickly replace a normal Maven Dependency JAR by its Eclipse project?
Currently I:
Remove the Maven Dependency (Right click on the JAR, Maven -> Exlude Maven Artifact)
Edit the Build path and add the corresponding Eclipse project
Mark the project also in the "Export and Order" section of the Build path
Edit the Deployment Assembly properties and add the Eclipse project there as well (so it goes into WEB-INF/lib at runtime).
If your web projects is a maven project (little "m" in the upper left corner) and you have installed the M2E-WTP plugin (included in the Keplar JavaEE package), this will happen automatically, i.e. when the dependent project is open in the workspace, it will be a project link, if it is closed, your web project will use the jar file as dependency.
If you are using M2Eclipse, I gess you should enable Workspace resolution.
Both projects should be maven projects.
If you're using mvn eclipse plugin, make sure, they both have a pom.xml and call :
mvn eclipse:clean eclipse:eclipse

How can I make eclipse make use of packages downloaded by maven?

When I use Maven compile, it will automatically download the depended java packages for me. Now, to debug the project, I import the project into Eclipse, but in Eclipse, the depended package is still missing. How can I get the packages? Or, can Eclipse use packages downloaded by Maven?
You don't really need to manually add all the dependencies downloaded by maven to the classpath in Eclipse. There is a maven-2-eclipse plugin which integrates maven with Eclipse. Using that plugin you can
import/create a project as Maven project or
convert an existing project into a maven project
Your Eclipse will automatically add all the downloaded dependencies on the class path everytime.
An alternative to the m2e eclipse maven plugin suggested by rocketboy is to use the maven eclipse plugin. This works from the command line (mvn eclipse:eclipse), and generates Eclipse settings for your project by downloading dependencies and putting them onto the Eclipse build path.

Getting m2eclipse to match maven's classpath

I've got project with a few sub modules.
mvn clean install
works absolutely fine. But in Eclipse with the parent project open none of the maven dependencies are available and so all my Java source files are full of indicated compilation errors (they're not listed in the build path for the project). If I open one of the sub modules as a project there are no indicated compilation problems.
I've tried running
mvn clean install eclipse:clean eclipse:m2eclipsemvn clean install eclipse:clean eclipse:m2eclipse
and choosing project / update maven dependencies. Refreshing, closing and opening the project and Eclipse, etc.
Any ideas? Thanks in advance.
Getting m2eclipse to match maven's classpath
Just use Import... > Existing Maven Projects and import your multi-modules Maven project, that's all.
But in Eclipse with the parent project open none of the maven dependencies are available and so all my Java source files are full of indicated compilation errors (they're not listed in the build path for the project).
A parent project (i.e. with a pom packaging) is not a Java project, it's just there as a facility to make editing the parent pom.xml from the IDE possible (and that's already nice, importing nested projects inside Eclipse was initially not even possible).
If I open one of the sub modules as a project there are no indicated compilation problems.
That's how you are supposed to do things.
I've tried running (...)
You are not supposed to use the Maven Eclipse Plugin when using m2eclipse and this is not supported. Either use one or the other. If you decide to use m2eclipse, use Import... > Existing Maven Projects as suggested.

Categories