Eclipse won't believe I have Maven 2.2.1 - java

I have a project (built from an AppFuse template) that requires Maven 2.2.1. So I upgraded to this (from 2.1.0) and set my path and my M2_HOME and MAVEN_HOME env variables.
Then I ran mvn eclipse:eclipseand imported the project into Eclipse (Galileo).
However, in the problems list for the project (and at the top of the pom.xml GUI editor) it says:
Unable to build project
'/export/people/clegg/data/Workspace/funcserve/pom.xml;
it requires Maven version 2.2.1
This persists whether I set Eclipse to use its Embedded Maven implementation, or the external 2.2.1 installation, in the Preferences -> Maven -> Installations dialog.
I've tried closing and reopening the project, reindexing the repository, cleaning the project, restarting the IDE, logging out and back in again, everything I can think of! But Eclipse still won't believe I have Maven 2.2.1.
I just did a plugin update so I have the latest version of Maven Integration for Eclipse -- 0.9.8.200905041414.
Does anyone know how to convince Eclipse I really do have the right version of Maven? It's like it's recorded the previous version somewhere else and won't pay any attention to my changes :-(

Eclipse allows you to specify an external Maven installation. But there's a catch. :(
Have a look at Windows > Preferences > Maven > Installations.
You will see a message like this:
Note: Embedded runtime is always used for dependency resolution, but does
not use global settings when it is used to launch Maven.
To learn more, visit the maven web page.
Translating to English, it means that Eclipse will continue to employ its internal Maven instance in order to perform some tasks.
When you "Run As > maven install" it will run your pom.xml script employing the external Maven instance you specified but when Eclipse performs some of its internal stuff, it will continue to use the embedded Maven instance, whatever version it is.
(edited)
As far as I know, when you install M2Eclipse you are implicitly defining which "internal Maven instance" you will have, which is exactly that one packaged by the plugin.
In the plugin configuration, you can add external Maven instances by telling where they are installed.

If you are using a recent m2eclipse version, you can try this too:
<prerequisites>
<maven>>=2.2.1</maven>
</prerequisites>
Notice the greater than in >=2.2.1. It works fine for me.

A common source of trouble (of this kind) is if you change global preferences and don't remember or know that you have enabled some project specific settings. At least it's a chance that the global setting is now set to use the external maven but the project setting is still set to 'embedded'.

M2Eclipse uses an embedded maven instance, not the maven instance you have installed on your system.

Have you tried switching workspaces?
You can still reference the same project in the new workspace. This would provide about as much of a reset as you can do in terms of eclipses internal settings.

Try creating your eclipse project with mvn project:m2eclipse or use the maven import option under import project.

Using m2eclipse, my fallback in these situations is to do Maven > Update Dependencies and then Maven > Update Project Configuration. The first is just me being supersticious, but the second will rewrite .project and .classpath.
As Pascal says about, m2eclipse can also be pointed at an external instance. I've done this in the past, though not at 2.2.1.
Dan

I got the same issue. Resolved it by restarting the system because every time you change the 'Path' in environment variables you should restart the system or else if would not pick the changes.

Related

eclipse vs cmd maven repositories

I am working on a project where there is quite a lot of dependencies loaded. I am using a specific settings.xml file which is pointing specific direction for the m2 repository. It set in eclipse preferences for maven to use this settings file and also as a environment variable to use this settings file.
Now, the scenario that I am no sure what happens is:
there was a change in the code that requires an update of the dependencies
you are using the Maven -> Update project... option from project context menu in eclipse, or using the Maven build with the Update snapshots option checked
Dependencies are downloaded and in eclipse you can see that the code is building again.
And here is the part that I do not understand, now I am trying to run simply "mvn clean install" on the specific project but it is not building, I need to use the -U option and when the dependencies are downloaded, then the build is success.
I know that this is long scenario and for someone probably a tl;dr but would be very grateful if someone could explain it to me why there is a need to download the dependencies double.
Usually, the Eclipse plugin uses an embedded maven that is different than the installed in your operating system. If you use custom settings, you must configure both.
In Eclipse, you can go to Window > Preferences, and look for Maven > Installation. You may check there the maven you are using. There is a default EMBEDDED maven. You can use a button to Add.. others.
In Window > Preferences, and look for Maven > User Settings to define your settings.xml file.
For external (typical) maven installations, the settings.xml file is located in your home directory.
To avoid double configurations (and repositories), I think you can
Configure Eclipse to use the same settings.xml, or
Configure Eclipse to use an external maven.

Do i need to use embedded maven for m2e workspace resolution to work?

In my previous pc I was working with linux, eclipse Indigo, m2e (I suppose v1.2 or v1.3) and maven 2.
I had configured m2e to use my external maven 2 installation, had projectA depend on projectB and without the need to install any of the projects to the maven local repository I could execute an Eclipse Maven Build (e.g: compile or dependency:tree) configured to use the external maven installation and to Resolve artifacts in workspace. That worked.
Now, I 'm using win7, eclipse kepler, m2e 1.4.1 and maven 3. I configured all in the same fashion (use external maven installation), create the same projects, use the same eclipse Maven build (run configuration) with workspace artifact resolution enabled and it don't work.
Right now it only works if i configure the maven build to use the internal eclipse embedded maven installation.
I 'd really like to always use my external instalation, does anyone knows if this feature was removed from m2e or should this scenario work as I expected and maybe it's a bug thats happening in my specific environment?
It's worth checking that the settings.xml for your external maven makes sense, and eclipse is configured to use it.
I 've tested in other similar environments obtaining same results but, when
upgraded to Eclipse Luna problem was solved.
If you 're facing similar problem, then upgrade to Eclipse Luna.

m2e in Eclipse Indigo no longer working

m2e is no longer working in my Eclipse Indigo. Nothing is printed to the Maven console, I can't download any sources and some dependencies won't be resolved.
I'm using the embedded Maven installation.
Do you know how to fix this issue?
Just a wild guess (due to similar problems I had in the past):
If you use the embedded m2e Maven installation, Maven has no information to your settings.
If you are in a corporate environment, you have to set your proxy in a Maven related location:
In your users settings.xml file.
In your Maven installation settings.xml file
m2e can only use the proxy set in your Maven settings file, not the one in your eclipse environment. So as a result, you could see all the old libraries contained in local repositories, but no new ones contained only in remote repositories located somewhere on the internet.
Please add some more information about your configuration in eclipse (does eclipse find your user settings.xml file?) and the errors you get.
Try -clean workspace option. Or if it doesn't help, create new workspace, test if m2e started working and import your old projects. I just resolved issue very similar to yours using second option.
Here is good explanation of such kind of troubles: http://www.eclipsezone.com/eclipse/forums/t61566.html

Maven m2eclipse detect changes in dependecy in workspace and automatically install

I found an annoying issue working with m2eclipse in Eclipse.
My workspace contains 2 projects, an application A and a library B. The application A POM has B as a dependency and everything works correctly. (The project dependecy is found and used when I build the application)
But if I change some code in project B and I forgot to mvn:install it, when I build the application it uses the last built version of the library and it loses my last changes.
Is there a way to force Maven / M2Eclipse to check if the source code of the dependecy is newer than the last version built, and to install it when installing/ deploying the main application?
Or maybe my approach is wrong or is something obvious that I'm missing?
You can tell m2eclipse to use resolve dependencies from the workspace rather than through the normal mechanisms. In your project properties (NOT workspace properties), select Maven->Resolve dependencies from Workspace projects.
This will mean that when you change B and subsequently build A, the changes should be picked up automatically.
If, however, you build outside Eclipse, you'll have to do the normal mvn install to get the correct dependencies.
I don't know of a way to tell maven to build the library first, then build your project. You could put two maven commands into a script and run the script.
Alternatively, you could put both projects inside a maven parent project, and then build the parent. This causes all child project to be built too (so in your case the library, and the application).
I think you have couple of options here
If you can change the maven project set up, I would suggest you to use maven multimodule
Option two might solve your problem but still involves a manual stop when you change your dependent project B, Do this on for your dependent project in eclipse
Select Library B ==> Properties ==> Maven ==> in the input box under Goals to invoke after project clean: ==> enter : install
To deploy any change that you made to Project B in eclipse to maven local/remote repo, You have to run Clean build in eclipse, This will deploy the latest Library B to the maven repository
Also make sure your Library B version is a SnapShot during the development
If you are looking to run the latest snapshots on your local machine you should try to set things up to launch directly from Eclipse.
Apart from avoiding the problem you originally posted about, it also has other advantages.
It will save you a lot of time by not having to perform intermediate build steps.
You can start and stop servers without having to leave your IDE.
The Eclipse console has extra features that you don't get from the system console.
You don't have to modify your start scripts to attach a debugger.

Why does M2Eclipse complain about missing artifact when mvn command line doesn't?

I've just set up a brand new installation of Eclipse Helios and have configured M2Eclipse to use an external (v 2.2.1) installation of Maven.
The system compiles fine on the command line, but from within M2Eclipse several of my project modules have an error:
Missing artifact javax.jms:jms:jar:1.1:test
I can get past the error by excluding the jms artifact from the Atomikos dependencies. But my main question is how can the two provide different results!
Even more odd is that I have another installation of Eclipse Helios and everything works fine.
The dependency resolver in m2eclipse is not using the external Maven installation, it has to use the embedded Maven version. So, I'd recommend to get the latest version of m2eclipse, as well as Maven 3.x version to minimize the difference in dependency resolution.
Additionally, it is possible that you had some alternative repositories defined in your maven 2.2.1 conf/settings.xml file. If you use the embedded maven3 these will be ignored.
You also can specify your maven 2.2.1 installation as the maven installation for m2eclipse.
I posted a similar question and finally found an answer. See m2eclipse says "Missing artifact" but I can build from cmdline!
You can find a different solution at http://getsatisfaction.com/sonatype/topics/_missing_artifact_from_m2eclipse_but_it_is_not_true
Same problem here: I use maven 2.2.1 as the installation to use from eclipse, as it is the one which works on the command line. Maven 3 does not work for this concrete project, complaining about some missing dependencies which, after much research, in my case turned out to come from old maven 1 repositories with legacy layout. Maven 3 hates these and will burst burst into cry when it finds them.
So maven 2 works just fine on the command line, but maven 3 does not. The problem with eclipse is that even if you specify maven 2 as the installation to build your projects, it uses maven 3 (the embedded installation) for dependency resolution, so if you are so unlucky to require a legacy repository you are screwed (I mean, eclipse won't help).

Categories

Resources