Make Eclipse reference maven projects and not jars - eclipse

I'm trying to have the projects within my workspace to reference each other directly, instead of the jar files from the maven repo. That used to work perfectly fine when having all the projects in the same folder (eclipse workspace) and using mvn install and mvn eclipse:eclipse. However, now it's not working and I believe it's due to the fact that the projects are not located in the workspace folder, but in my local GIT repo, from where I import them into Eclipse. I assume that I need to set some variable somewhere, but couldn't find anything on this on the interwebs. I've also tried using the eclipse maven plugin, but I got into other problems that completely broke my setup. Using -Declipse.useProjectReferences=true doesn't help either. I'm grateful for any hint!

I suddenly began having this problem after a reboot (??).
What worked for me was:
on my project's context menu, open "Properties"
Java Build Path tab: add the projects which need to be referenced
Order and Export tab: move these projects to the top of the list

There's a setting on each Project to control this behavior. Right-click to open the project Properties, then select the Maven section; there you'll find the option Resolve dependencies from Workspace projects.

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?

FindBugs plugin does not work on projects imported from GitHub

I have always used FindBugs, and it is really useful in many cases. But I couldn't get to find why it does not work on projects imported from GitHub. Projects imported into Eclipse using Git as the source does not have an option to run FindBugs.
Does anyone know why, and a solution to this? I do love to use git extensions on Eclipse, as well as FindBugs.
Is the project that you imported from Git recognised as a Java project (i.e. it has a J under the project folder icon)? If not then FindBugs won't be enabled for the project. If that's the case the remote repository almost certainly hasn't added the .project and .classpath files which are what Eclipse uses to determine if it's a Java project or not.
You should be able to convert it to a Java project by right-clicking and doing 'Configure -> Convert to Java Project'. If that doesn't work, delete the project (but without deleting the files) and then create a File -> New Java project in the same location.

Importing maven sourceproject into eclipse

I have imported my maven project in eclipse using Import Maven project. It got import in eclipse project explorer, but all the source folder are opening as files and folders, its not opening as java source folder. Since its opening as files and folder, it doesnot have compilation unit, found very difficult to code using it.
What do I need to do inorder to make the source folder as java source folder so that I can code easily?
Select the project and from the context menu choose Maven -> Update Project Configuration (This menu item gets reworded across various maven releases so look for something similar). You may also need to choose Update Dependencies.
In the shell/command line, execute mvn eclipse:eclipse

maven integration in eclipse new project checked out but can't navigate

I am struggling with maven in Eclipse even though I have m2e.
I checked out a maven project from CVS and cannot navigate anywhere. If I try References > Project, I get a pop up saying:
"Problems opening an editor Reason: services does not exist".
services is the name of the main project, which has sub projects within it. It all builds successfully so I am not sure why Eclipse does not work.
I suspect something related to classpath but have no idea how to edit it since it is not available from the project's properties. I actually tried to manually create a .classpath file but it did not help.
I also converted the project to a maven project but that did not help either.
Any ideas? I am using Eclipse JUNO.
I figured out my issue. I had to check out the project from CVS. Then (that's the important part), perform a maven import of an existing project within eclipse. That created maven "ready" projects where I could use all of the IDE's functionality.
Yes, you're right. If you import directly from a repository, hovering, linking and opening declarations isn't gonna work. Your solution is right, although another one more direct is use the "File->New->Other->Maven->Checkout Maven Projects from SCM". If then, you have problems because you can't select any SCM type, check Checkout Maven project from SCM - no connectors. If with connectors installed you still have problems: http://forum.springsource.org/showthread.php?102665-SCM-types-not-available-in-Checkout-Maven-Projects-from-SCM.
If you have checked out project from svn, project checked out is not generally a eclipse project thats why general functionality of eclipse does not work for the same.
To achieve the same functionality of eclipse like eclipse reader and all other shortcuts,we have to convert the checked out project to eclipse project.
Steps to Convert checked out project to eclipse project:
Right Click on Checked-out Project.
Point to Configure.
Click on Convert to Maven Project.(if checked out project is maven project)
These steps will convert the project to Maven project.
All the eclipse functionality will work for the same.
In addition to ensuring that the projects are configured as Maven projects, you may also go to Project Properties (right-click on the project in Package explorer) > Project References, and add projects in the workspace that the selected project may have references to.
I had this problem, too.
It looks like after a search-in-workspace Eclipse opened a wrong file.
I pressed Strl+Shift+H (Open Type in Hierarchy), typed in the class name, and opened it. The file opened in a new tab, and everything was navigable again.
The difference in icons is:

How do I reinstall Eclipse without losing my projects and plugins?

My Eclipse recently broke completely and I have upgraded to Galileo. I have created a fresh workspace (say foo/workspace) and created a trivial project. I have then copied an old project from (bar/workspace/myproject) to foo/workspace/myproject. It is mavenised and has a pom.xml. How do I tell Eclipse to build it (it does not seem to recognise it is mavenised). Do I have to install the maven plugin?
In general what is the smoothest way to reinstall Eclipse (i.e. what else do I need to think about?)
I never create or checkout a project directly under the Workspace but rather use something like ~/Projects for all my projects. This allows me to remain IDE independent. Actually, I never use any IDE to create a project.
I share my workspace location across several Eclipse install (specified at startup or using -data). If anything goes wrong, I don't mind deleting and loosing my workspace, it doesn't contain anything really important anyway.
Use the m2eclipse Eclipse plugin to Import > Maven Projects into Eclipse. Another option is to use the maven eclipse plugin to generate the .project and .classpath from the command line and then to Import > Existing Projects into Workspace from Eclipse.
It is better to reference directly your old workspace when starting your new eclipse installation: see this eclipse.ini
-data
c:/a/path/to/your/old/workspace
That way, you get back all your projects.
You can install the m2eclipse maven plugin by adding its update site to the list of sites examined by the eclipse p2 provisioning mechanism
http://m2eclipse.sonatype.org/update/
If the metadata associated with your workspace is messed up, and it sounds like it is, the easiest thing to do is simply delete the .metadata folder from the workspace (or rename it to something else). Start up Eclipse, it will show an empty workspace, and then use File -> Import to import existing projects back into your workspace. Just point it to the folder of the existing project and it will do the right thing, leaving the project in place.
For the maven stuff, the Import Maven projects mentioned above seems right and probably does some other stuff to have maven work out.