Eclipse Indigo with m2e can't find maven dependencies in a multi-module project - eclipse

I've created a multi-module project using Indigo with m2e 1.0. One of the child modules has a dependency on the other. It all builds correctly under maven.
Eclipse, however, can't find any of the classes that this module uses from the dependency .jar. The project properties shows the artifact under Maven Dependencies, but it does not show the actual .jar file itself.
I added the dependency with the Maven menu for this project.
The .project and .classpath got generated automagically at some point. I did not have to run mvn eclipse:eclipse or mvn eclipse:m2e (or whatever the goal is for m2e). The .classpath doesn't have the dependent .jar in it, but it does have org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER.
I've tried all the options under the Maven menu (update dependencies, update configuration) and refreshing the project. I've closed and re-opened Eclipse. It still shows errors.
This makes Eclipse worthless as a Java editor in multi-module projects. I could manually add the dependency .jar in the .classpath, but this defeats the purpose of integration Eclipse and Maven with m2e.
Is there any solution for this in Eclipse?
Thanks.

The answer turned out to be the last answer to this question given by Jody Box. It's pretty bizzare that in order for Eclipse to resolve dependencies from another project in the Workspace that you have to uncheck the "Resolve dependencies from Workspace projects" checkbox.
I know mvn can be convoluted but this checkbox is doing the opposite of what it says.

Related

Running Eclipse project with maven dependency to another project in same workspace?

In my workspace i have many maven projects with dependecies between them managed by maven.
When i try to navigate through the types it shows the maven installed artifact and not the actual class in the workspace residing in another project.
It will be of much help if eclipse autoresolves the maven dependency and point to the local project instead of installed artifact. Is there any we can force that.
Thanks

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

How eclipse maven and ant work together?

I made simple maven project and I opened it with Eclipse. I have installed maven plugin for Eclipse. I'm interested in following:
How Eclipse compiles code when I hit save on my source code (does it use configuration from ant or maven or something else)?
When I run tests from JUnit plugin for Eclipse those Eclipse calls mvn test (I suppose not, but what is then happening exactly)?
Is it possible that maven does the build successfully but Eclipse is
showing errors in code?
The Maven Integration for Eclipse makes it easier to edit POM files, allows you to execute maven builds from within Eclipse and to help with dependency management. It doesn't actually compile your code (unless of course you execute a maven build from within Eclipse). The main help is with the dependency management and writing the .classpath file of your project within Eclipse.
To try and answer your questions:
Eclipse uses its standard mechanism to compile code. With a standard eclipse for java developers your project will have a Java Project nature and Eclipse will then use the Java Development Tools - JDT to compile the code. (Internally this uses an incremental builder to build the code http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresAdv_builders.htm). What source files it will compile and where it will place the resultant .class files is configured in your project's Java Build Path (which I am guessing the maven plugin may well configure for you)
JUnit support is part of the Java Development Tools as well.
It is possible that maven will successfully build a project outside of Eclipse, but that the same project will show errors within Eclipse. This is usually down to classpath errors (dependencies defined in the project's POM not being added to the classpath in Eclipse). If you are using the maven plugin with eclipse this probably shouldn't happen. If you are not using the maven plugin within eclipse you can execute maven eclipse:eclipse to have maven update the Eclipse .classpath file of the project which should then fix any of these problems.

How can I add a classpath entry as a publish/export dependency in an Eclipse dynamic web project?

I successfully created a project using Wicket quickstart and turned it into an Eclipse dynamic web project by running
mvn eclipse:clean eclipse:eclipse -Dwtpversion=2.0
I imported the project to Eclipse without any issues, but got this warning for each JAR:
Classpath entry M2_REPO/**.jar will not be exported or published.
Runtime ClassNotFoundExceptions may result.
I can fix this by using right click → QuickFix on each warning and selecting "Mark the associated raw classpath entry as a publish/export dependency," but this takes a lot of time and would not be possible if there were a lot of dependencies.
There must be a way to have Maven do this for me; what is it?
EDIT: I've found out that using m2eclipse core + Maven Integration for WTP (from m2eclipse extras) resolves my issues.
I'm still interested in how to achieve this without m2eclipse, though, just out of curiosity :p
The two Maven plugins needed to work with web projects in Eclipse are available from the Eclipse Marketplace.
Maven Integration for Eclipse (included in the Java version of Eclipse)
Maven Integration for Eclipse WTP