Eclipse Maven Projects False Error - eclipse

I have a parent Maven project that consists of several other projects. When i am building the project in command line everything is fine.
Then i open my Eclipse and the workspace is full of errors (which are actually false positives).
In order for me to get rid of this errors i have to do a "Run As... -> Maven install" and then a "Maven -> Update project..." on every project from within eclipse.
Is there any way or any plugin that can actually refresh the workspace and update the maven dependencies on each project, so that i can avoid this tedious operation?
Does anyone else face the same problem when using Eclipse as an IDE for his/her maven projects?
UPDATE
It seems (as in most of the cases with eclipse) that the problem was with the M2E plugin. Somehow the plugin was picking some settings in the .metadata folder in my workspace. I deleted the contents of the folder, restarted eclipse, re imported everythings and now it seems to behave as expected.
Hopefully, in newer version Eclipse will support Maven in a proper manner.

It could be that some of the files are just out of date. When I get this I do a refresh of the affected projects and then clean the workspace (Project -> Clean...) cleaning all projects.
If the refresh and clean don't do the trick, then I'd suspect that your maven settings in Eclipse point to a different set of repositories than does the command line maven's settings.xml. Go into the maven property page in Eclipse preferences and confirm that you're using the same settings.xml (re-select just to be sure).

Related

Maven multimodule projects linking in eclipse

I have a maven multi module project which has 5 modules. Some of my modules depend on one or more other modules, I am successfully able build the project and in eclipse also I am not getting any errors. However there is one problem which is bothering me, when i ctrl + click in my code and the class is defined on some other project eclipse does not open the file in the editor. I know i can attach the source code using maven but still i wont be able to make changes to that file.
Is there any way to be able to link projects in eclipse through maven?
Is there any way to be able to link projects in eclipse through maven?
That behaviour is the default. To check if for some reason that default is not in effect for your project, right click your project (the project you want to jump from) and go to "Maven". If there is an option "Disable Workspace Resolution" the workspace resolution is switched on, meaning you can theoretically jump from that project.
If you still cannot jump, then the project you want to jump to is not in your workspace. Take into account that for eclipse to identfy one project as dependency of another, everything including version must match.
Also check what rest_day said. You must have the projects importet as maven projects, but running eclipse:eclipse is not required anymore with current (up to ca 2 year old) eclipse.
Did you import the projects as Maven projects?
Also, could you go to the root of the project and run mvn eclipse:eclipse
eclipse:eclipse
Full name:
org.apache.maven.plugins:maven-eclipse-plugin:2.10:eclipse
Description:
Generates the following eclipse configuration files:
.project and .classpath files
.setting/org.eclipse.jdt.core.prefs with project specific compiler settings various configuration files for WTP (Web Tools Project), if the parameter wtpversion is set to a valid version (WTP configuration is not generated by default)
If this goal is run on
a multiproject root, dependencies between modules will be configured
as direct project dependencies in Eclipse (unless useProjectReferences
is set to false).
Instead of Ctrl+Click, click on the identifier and press F3. If you now see a red text reading "Current text selection cannot be opened in an editor", you've been hit by this bug.
See this question for a solution: How do I get rid of "Current text selection cannot be opened in an editor" in Eclipse?

Automatically update a maven project under eclipse, after a svn-checkout

After checking out a maven project from a svn-repository, eclipse shows dependency-errors.
To solve the problem,
I have to right-click on the project-folder,
then I have to click Maven --> Update Project
After doing that, the dependendicies of the pom-file are downloaded and the specific classpathes are set.
The problem: I have to do this everytime after a checkout of a maven-project.
My question: Why should I have to update manually the maven-project? Why didnĀ“t do this the maven-builder automatically? Is there any way to engage eclipse or the maven-builder to do this automatically?
If you have Subversive (installable via the Marketplace), you can checkout and set up the project in one step from Eclipse. In the dialog File -> Import try the entry Maven -> Check out Maven Projects from SVN.
Unfortunately, maven project configurations tend to get stale when you're changing stuff in the POM. Another tip from me is use the keyboard shortcut for "Update Project" (Alt-F5 on Mac & Windows) which should select the project you're currently in and has the option to update all projects at once.

An internal error occurred during: "Updating Maven Project". Unsupported IClasspathEntry kind=4

As the title mentioned I have the following problem: I use Eclipse with Maven Nature and when I update my Maven Project, I get this error:
An internal error occurred during: "Updating Maven Project".
Unsupported IClasspathEntry kind=4
The solution that always comes back is the following:
rightclick project, remove maven nature
mvn eclipse:clean (with project open in eclipse/STS)
(sometimes they suggest to do mvn eclipse:eclipse next)
rightclick project and reenable maven nature
Now I exhaustively tried all combinations several times. But I always keep getting the above error. The error starting occurring when I had to mvn eclipse:eclipse the project. Before it was always running fine using only m2eclipse features and setting everything in eclipse.
I had to do it slightly different to work for me:
rightclick project, remove maven nature (or in newer eclipse, "Maven->Disable Maven Nature")
mvn eclipse:clean (with project open in eclipse/STS)
delete the project in eclipse (but do not delete the sources)
Import existing Maven project
I just went to Properties -> Java Build Path -> Libraries and removed the blue entries starting with M2_REPO.
After that, I could use Maven -> Update Project again
This is all you need:
Right-click on your project, select Maven -> Remove Maven Nature.
Open you terminal, navgate to your project folder and run mvn eclipse:clean
Right click on your Project and select Configure -> Convert into Maven Project
Right click on your Project and select Maven -> Update Project
After trying all these procedures it still didn't work for me. What did work was
go into File Explorer and delete the .classpath file under the project's root folder
run Maven update within Eclipse, and check Force update of Snapshots/Releases
Our current work required integrating a number of disparate projects so unfortunately use of SNAPSHOTs in a production environment were required (taboo in Maven circles)!
This issue (https://bugs.eclipse.org/394042) is fixed in m2e 1.5.0 which is available for Eclipse Kepler and Luna from this p2 repo :
http://download.eclipse.org/technology/m2e/releases/1.5
If you also use m2e-wtp, you'll need to install m2e-wtp 1.1.0 as well :
http://download.eclipse.org/m2e-wtp/releases/luna/1.1
Slightly different option usually works for me:
"mvn eclipse:eclipse" for this project in the command line.
"Refresh/F5" this project in eclipse.
That's all, no need to re-import but need to have the terminal window handy.
I solved this by looking at this comment on JBIDE-11655 : deleting all .project, .settings and .classpath in my projects folder.
I have that problem and my solution is going source folder and run command line: mvn clean install -DskipTests eclipse:eclipse then return eclipse workspace and refresh project. Hope that help!
Your command line mvn eclipse project generator may not be the same version as that of your eclipse, and eclipse doesn't understand for your command line tool is generating.
Just use eclipse's in this case:
remove the project from eclipse (including all modules if multi-module)
run: rm -rf .settings/ .project .classpath to delete eclipse project files, also from modules
import your project as an existing maven project
I imported the project as general project from git repository.
Deleted .settings, .project and .classpath in project's folder
Configure -> Convert to Maven Project. Only this solved the problem in my case.
I removed my .classpath file in my project directory to correct this issue. No need to remove the Maven Nature from the project in Eclipse.
The specific error I was getting was: Project 'my-project-name' is missing required Java project: 'org.some.package-9.3.0 But my project wasn't dependent on org.some.package in any way.
Perhaps an old version of the project relied on it and Maven wasn't properly updating the .classpath file.
It helped in my case
rightclick project, remove maven nature
mvn eclipse:clean (with project open in eclipse/STS)
delete the project in eclipse (but do not delete the sources)
Import existing Maven project
My tricky solution is:
Open your windows Task Manager,
Find the Javaw.exe process and highlight it, then End it by End Process
In eclipse project browser, right click it and use Maven -> Update Project again.
Issue is resolved.
If you have Tomcat Server Running in Eclipse, you need to refresh project before restart Tomcat Server.

Searching for dependencies returns nothing

I've just installed Eclipse Juno with m2e installed.
Then, I've created a new Maven project and decided I want log4j, so I opened the pom.xml, clicked on the Dependency tab, clicked on the Add... button and typed in log4j.
Zero results. The only thing that it finds is junit (that was automatically added to the project with the quickstart archetype, it seems). Note that I can add the log4j dependency manually and it will work just fine, but I find the search feature really convenient!
I'm a kind of a Maven beginner, though I got m2e working no problem in Indigo. So I'm thinking I might have forgot to set something?
All you have to do is update or rebuild your workspace maven repository index.
Open your "Maven Repositories" view. Open Global Repositories and right-click on central. Enable full index and rebuild.
Initially the process will take several minutes. After that your search will start working.
You can automate this process by turning Download repository index updates on startup on in your workspace preferences under Maven
in case rebuilding your workspace maven repository index didn't work, try reinstalling m2e. I updated mine via marketplace and it started working again. I'm not sure what was the issue but I suspect some URLs got changed recently.
Just go to Window -> Preferences -> Maven
and check the option Download repository index updates on startup and click Apply. That's all.

eclipse project not importing the jar packages in local Maven repository

I am facing a problem in setting my eclipse project.
The problem is whenever I am creating a new project and import the code.Eclipse is not resolving the packages which are present in the jar files which are present in the C;/..../user/.m2/repository.
Hence it's giving a lot of compilation errors until I add all the required jar files manually in the build-path by going to "Add External Jars"
I saw that M2_REPO is present in my Eclipse classpath.But still it is not resolving the packages.
Please suggest how this problem can be resolved.
Gaurav
I've been having a similar error in Eclipse on OSX. In Eclipse on the Mac, there is no "Maven" entry when you right-click on a project in the explorer.
However!
I just discovered that if I right click and then click "Validate", it suddenly magically resolves all the dependencies. No idea why, but maybe this will help.
I've had this issue on Eclipse Kepler EE which comes prebuilt with m2e, I finally got it working by doing the following on each project:
Right click on the Project
Select Properties
Select Maven
Uncheck the option that says: Resolve Dependencies from Workspace projects
It should pop up with a box that says Maven setting has changed. Do you want to update project configuration. Click Yes to this.
To confirm:
Right click on the project
Select Properties
Select Java Build Path
Check the Libraries tab under Maven dependencies that all the jar you
expected are now there.
close your project, and remove your project settings files: .project, .classpath, .settings/. Then re-import this project. It will be ok.
Though this answer is late. But it can help the future audience.
You can give it a try using Project(Right-Click) -> Maven -> Update Project. To select all or the number of projects you want to update.
This worked for me.
Have you put all needed dependencies in the pom.xml? Even if the Jars are already in your local repository, each project needs its dependencies mentioned in the pom.xml to resolve the dependencies. If you do that, m2eclipse will automatically resolve the build path.
Another possibility. Are you running Eclipse using JDK or JRE - the default is JRE. You will see a warning in Eclipse console, if so.
maven eclipse plugin will not work correctly unless run with JDK.
I just had a similar problem. The JDK was there, the problems view was set to Show All, and yet there were hundreds of unresolved type errors. Not even Refresh (F5) would work.
In the Project|Properties|Java Build Path|Libraries window I was seeing only the JRE System Library, but not the desired "Maven Dependencies" entry. And "Maven Dependencies" was also missing from the Package Explorer view as well.
I finally fixed this by right clicking on the project in the Package Explorer, selecting Maven from the menu, then selecting "Update Project Configuration." This added "Maven Dependencies" and all the errors went away.
This was nice because prior to this fix I had to treat Eclipse like a dumb editor and run mvn compile on the commandline to find errors.