Eclipse m2e plugin stopped changing classpath to add dependencies - java

I have used the m2e plugin in luna 4.4.1 for a while for handling dependencies and it worked fine. Normally, I create new Java projects then convert them into a Maven project.
I decided I wanted to start using the standard Maven directory layout, so for my most recent project I created it as a Maven project and then added the Eclipse Java facet so that Eclipse would treat it like a Java project.
This has broken Maven, so that it is no longer making it's dependencies available to new projects. Normally, Eclipse adds a "Maven Managed Dependencies" library to a project with Maven dependencies; new projects no longer do this and the dependencies are never added to the project classpath. Projects that had been working before still add and remove them normally.
I have narrowed the problem down to a .classpath error; for some reason m2e has stopped modifying the project classpath to make it's dependencies available. I can work around it by manually copying and pasting the entries from a working project but I would like to find a way to "re-automate" it correctly.

I have sidestepped the issue by finally buckling down to learn Gradle.

Related

Java plugin for Visual Studio Code cannot load Spring Boot classes when start debugging a multi-module Maven project

I am using Visual Studio Code with Red Hat Java Plug-in and Debugger for Java plugin. I got a problem that:
1) If I work with a single module Maven project, everything is ok.
2) But if I open a multi-module Maven project, the debugger cannot start because of "java.lang.ClassNotFoundException: org.springframework.boot.web.servlet.support.SpringBootServletInitializer"
3) The project can be built with Maven, and running the Jar is all right
I guess the problem is because of the classpath settings, however to my understanding, the .classpath file should be derived from the POM file, which should be correct, otherwise Maven would have not been able to build the project.
I did not manually modify the launch.json, and the plug-ins generated the settings for me.

Make maven generate dependencies even with errors

This feels like a really stupid question but I haven't been able to find an answer.
I'm working on a maven project but I do most of my development in eclipse. Is there any way for me to force maven to generate all of my dependencies under target even if there are errors in the code? I set my eclipse project's build path to use the jars under target/dependencies/jars, but calling mvn clean kills them and if there are any errors in my code causing it to not compile mvn package won't create the dependencies but will instead just crash saying BUILD FAILURE. This makes the problem even worse since instead of seeing the actual errors my eclipse will just bombard me with errors everywhere since all of its dependencies just died.
Or maybe the way I'm working with it is just stupid and there's a better way.
Are you using the m2e plugins for Eclipse to process maven projects, or simply importing the projects as general ones?
If the latter, you should use the m2 plugins (simply go to the Eclipse Marketplace and search for Maven), as they interrogate your POM and set up your dependences properly. You can then concentrate on any compile errors in your code.
You should not point to the jars in the target folder for dependent JAR's since this is where the products of building your project are stored. Performing a mvn clean removes this folder.
To use Maven with Eclipse install the m2e plugin in Eclipse. This makes Eclipse understand the structure of Maven projects.
Once installed you can import your Maven project into Eclipse. I use Import... | Existing Maven Projects for this. But you can also directly import form a versioning system.
During the import Eclipse will set up the Eclipse project to use the Maven dependencies to locate the required JAR's. These are taken from the repository as configured with the used Maven installation.

How and where does a pom.xml will be configured to be invoked by a web project

I have been working on maven for some time but never had this question before, Many times I created my maven project using a IDE wizard which helps me to create a maven project which has pom.xml pre-configured or the other way is to convert a general java project into maven project which generates a pom.xml. I have a question what exactly happens in the background when we convert this java project into a maven project. What will be configured and how does the java project detects it has a pom.xml.
Inside the .project file in the root of the Eclipse project, m2eclipse will add the org.eclipse.m2e.core.maven2Nature to it. This tells Eclipse that the m2e plugin will handle various stages of the project lifecycle, and m2e has a hybrid partially-internal and partially-external engine that applies the instructions in the pom.xml to the project. (For example, it finds the classpath placeholders that are marked as maven.pomderived and replaces them with the appropriate Maven dependencies.)

How to use Maven with EAR

If i want to convert an EAR project a maven project , do i need to add the module in the deployment assembly as maven dependency or just use the convert in m2eclipse without any further configuration.
Me personally I wouldn't attempt any kind of conversion of an existing project. I would add the poms, make sure that mvn clean install works on the command prompt and then create a new mavenized Eclipse project from the poms.
The main reason is that you current project settings are effectively wrong when you switch to Maven - the Maven poms are the truth and what feeds the Eclipse project setup, so you really do not want to make your life difficult and work against m2eclipse - let it do the project creation for you. Fresh.
You can install m2eclipse and then do the following as well.
Go to the project menu (right click on Package Explorer) > Configure > Convert to Maven Project
Open the pom.xml and right-click and choose Run As -> Maven Clean. Similarly Choose Run As -> Maven Install.
Note : Please ensure that your eclipse project settings are correct and classpath libraries are not absolute and you don't have any project specific environment variables defined in your workspace. Please take a backup of your project before you do this.This is to ensure we don't mess up the current stable project configurations. Once m2eclipse generates the pom.xml for your project, you can update and make changes to it to
fully obtain a mavenized ear build. hope this helps
You can also try creating new maven project with archetype selection of "jboss-javaee6-ear" and follow the similar structure for your project. Most probably you will need parent Pom and child poms per each module (ejb, war, jar etc). There are other few similar approach but almost all of them requires you to have mulitple POMs
maven-ear-plugin and JBoss AS 7
You can also go through all the examples for maven ear plugin to find settings suitable for you
http://maven.apache.org/plugins/maven-ear-plugin/
I ended up ditching ear for war :) single POM and even ditched the JBOss for tomcat/jetty :)
If you want to convert your existing eclipse dependencies into Maven dependencies, you can try the JBoss Tools (JBT) Maven integration feature, which contains an experimental conversion wizard, plugged into m2e's conversion process : http://docs.jboss.org/tools/whatsnew/maven/maven-news-4.0.0.Beta1.html.
So, all you have to do is, as Keerthi explained, right-click on your project and Configure > Convert to Maven...
If your dependencies already are maven artifacts, it should work easily. If not, you'll need to convert them to Maven (if they're workspace projects) or make them available in your maven enterprise repository, before converting the EAR project.
JBT (requires Eclipse JavaEE) can be installed from http://download.jboss.org/jbosstools/updates/stable/kepler/ or from the Eclipse Marketplace (See https://marketplace.eclipse.org/search/site/jboss%2520tools)

How do you refresh maven dependencies from eclipse?

We recently started using maven for dependency management. Our team uses eclipse as it's IDE. Is there an easy way to get eclipse to refresh the maven dependencies without running mvn eclipse:eclipse?
The dependencies are up to date in the local maven repository, but eclipse doesn't pick up the changes until we use the eclipse:eclipse command. This regenerates a lot of eclipse configuration files.
Have you tried using the m2eclipse plugin? I use it with eclipse and it maintains the eclipse .classpath when I add dependencies. It'll also check for updated dependencies.
You generate the special eclipse files with mvn eclipse:eclipse, but once you've done that, you should let a plugin handle the dependencies while inside eclipse.
That's how we do it at my work place, and it generally works well.

Categories

Resources