How do I interact with Maven goals using Eclipse/STS? - eclipse

I am learning Eclipse, and I'm trying to find out how to interact with Maven goals visually in Eclipse/SpringSource Toolsuite. In IDEA, there is a nice Maven menu on the right-hand side of the IDE that is put there by default - no extra user configuration is necessary to make this show up there.
How can I get the same thing in Eclipse? It seems weird that this is not enabled by default. I've looked in the "Window" section of the IDE and I also don't see it either. The only window dealing with Maven is the repository listings... which is not what I want.
Do people use the command line instead? How can I get the same thing that IDEA has?

If it is eclipse, get M2Eclipse plugin installed for your eclipse.
Just go to Help -> Eclipse Market Place and try to Find "Maven
Integration For Eclipse". In the results choose "Maven Integration
For Eclipse" and install it.
Then, if the project in your workspace is a Maven Project right click
on it and choose Run As -> it will show you some default goals
like clean, install, etc.. If you want to run other goals choose run
configurations and in the left part of the window, you will find an
option Maven Build. Right click on it and select New -> then you will
be prompted to choose the project and enter the goals you want to
execute...

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?

How to run an eclipse m2e webapp project on a local server?

I'm trying to create a simple webapp as a maven project with m2e to help me manage dependencies, but I'm must be missing something, because I'm not able to run the project from eclipse.
To put a bit more context, here is what I do:
First, I choose to create a "Maven project"
Then, I select the "maven-webapp-archetype"
Finally, I fill the basic project information form of the next step and finalize project creation. Everything looks fine at this point.
The problem is that when I try to run the project, I don't find anything suitable to run the project on a local server:
Also, from the "Add and remove..." context menu entry of the local server, my project doesn't appear in the list of web projects.
Did I miss a step in the setup, or is there an other more suitable way to start the project?
You should install the m2e-wtp connector.
You can install this from: Window, Preferences, Maven, Discovery, click Open Catalog and search for wtp. Check the box next to m2e-wtp, and click Finish.
Once the installation process has completed, allow it to restart Eclipse. After that, you may need to right click on the project, choose Maven and Update project.

How do I import a multi module Maven project from SVN into Eclipse (Indigo) so that child modules can be built independently?

I have tried posting this question on the Eclipse Maven forums but it seems very quiet there so here goes...
My setup:
-Eclipse Indigo Java EE bundle
-m2e
-Subversive
We have a fairly simple multi module maven project on our repo. It has a parent project/pom and 3 child projects/poms.
Steps I am taking to import:
1) I import the project by using "import->import->->Maven->Check out Maven Projects from SCM".
2) On the next dialogue box I select svn as the SCM URL type and enter the rest of the repo URL. I leave the check boxes checked for "Checkout Head Revision" and "Checkout all Projects" and under "advanced" I leave the check box "Resolve Workspace Conflicts" checked too. I do not enter anything under "Profiles" or "Name Template".
3) On the next dialogue box I leave "Use default Workspace location" checked and leave "Add projects(s) to Working set" unchecked and click "finish".
4) I wait a minute or so for the next dialogue box to appear. It asks me to select maven projects and has a file structure as it should be-parent project/pom and 3 child projects/poms with a checkbox beside all 4 items. I have tried to select either just the parent, just the children or all 4 without success.
5) When I select just the parent and uncheck the children above, the project appears to be imported. The parent appears in the project explorer and the three children appear as sub-folders of the parent with each having a pom.
6) If I right click on the parent, I get a Maven item in the context menu and indeed I can "run as->Maven build, install etc.." ON THE PARENT ONLY. The Child projects have no such Maven context menus nor the ability to "run as->Maven x".
If I try to import all 4 projects in step 4 above, it imports with the same structure as outlined in 5 above but with the children appearing additionally as separate "independent" Maven projects (with errors).
Ultimately I just want to import the multi-module Maven project and be able to deploy it on my Eclipse Tomcat installation, so if I change a file in one of the child projects (called frontend) the change will be deployed quickly and I can check the effect out in a browser.
Thank you very much for any and all help with this issue! I am happy to answer any further questions to help trouble shoot the problem.
My projects occasionally also lose this ability (though they have it right after import). Usually it helps to refresh Maven configuration, refresh/clean projects, or restart Eclipse. Note that it should still be possible to run it the long way, so "Run -> Run Configurations -> Maven".
I'm running Helios SR 2, m2e 1.0.0.20110607-2117.
Pretty sure each module would have to have it's own .project settings that you would need to commit.
Did you install the m2e WTP extension? At least in theory that should be a better option than tinkering with project settings outside of Maven/m2e control.
I probably explained the problem poorly in my initial question. The main problem was that I was not able to deploy the webapp component of the multi-module maven project to Tomcat. I was making a couple of basic errors:
I was importing the parent project without selecting the children, assuming Maven would get them all and that would suffice, but it did not: I had to select the parent and all children when importing as Maven project from svn.
I then failed to convert the webapp part of the project to a faceted type, and further failed to select "dynamic web app". I needed (according to a colleague) to then select version 2.5 to avoid incompatibilities with older servlet containers. (not sure how relevant this is to Tomcat 6, which is what I use).
Once this was done I had the parent project and 3 subfolders and also the 3 child projects in their own right appearing in the project explorer (but on file system they all exist under the parent project, as it should be). I could then right click on the webapp module (the eclipse project explorer project, not the subfolder) and run as Maven project (clean, build etc.).
I could then right click and "run on server". I had an error upon publishing about various files being out of sync. I just refreshed the child projects in eclipse and then they would publish successfully.
Eclipse has so many versions, with so many incompatible plugins etc. that it gets confusing very quickly-lots of the tutorials are highly specific to particular versions etc.
Thanks for helping anyway guys.

How to make Eclipse work with the snippet macro in maven doxia files?

I want to use the snippet macro in my maven site documentation in order to allow for testing of my examples code snippets with JUnit. But I don't want Eclipse to show the red "there is a build error" marker for all of my projects (which it does since m2eclipse does not recognize the snippet macro). I do want maven dependency management to be enabled for the projects in Eclipse, so disabling the maven integration completely is not an option. Moving to a different IDE is not an option either since I cannot force all of my coworkers to switch from Eclipse as well.
I would like a solution to either:
Make the Doxia integration in (m2)Eclipse recognize or ignore the snippet macro
Make Eclipse ignore errors in apt files altogether
Uninstalling the Doxia support is one solution.
Under the Help menu, click "Install new software", then "Already installed".
Select the "Maven Doxia" bundle and click "Uninstall...".

eclipse debugger: attaching source-code of maven dependencies?

I'd like to use the source code of maven-managed dependencies when debugging our webapp in myEclipse 8.
I have managed to attach the sources to the libraries in the "Maven Managed Dependencies" classpath container, i.e. when I open a class file from a dependency (e.g. using Ctrl-Shift-T), I see the source code.
However, when I define a server connector for my tomcat, deploy the wepapp to it, and launch it in debug mode and execution halts on a breakpoint in that same class, the editor pane only displays the text "source not found", and a button to edit the "source lookup path". I have attempted to manually add the "Maven Managed Dependencies" classpath container, only to be told "Use maven project settings to configure depedency resolution". However, I see no useful setting in that property pane ...
How can I attach those sources? I am aware that this works with the m2e plugin and wtp, but I'd rather avoid convincing the rest of my team to switch plugins ...
Looks like issue MNGECLIPSE-983
I have confirmed that if I manually pick the External Archive option and find the relevant -sources jar (navigating that big .m2/repository tree to find it) and then add the jar as a sources it does work, and surprisingly it does remember the next time which isn't too bad.
That's at least doable I think for me because we don't often need to step debug through external dependencies, but when we do, it's often frequent, so adding it once while a bit of a pain, can be done on a case by case basis.
I have since discovered that this problem only occurs if the server is launched using a launch configuration.
The problem does not occur if the server is started by:
click the server icon in the toolbar -> context menu appears
mouse over the intended server -> submenu appears
click on "Start"
While this precludes sharing the server configuration by checking the launch configuration into version control, it at least allows seamless debugging.
Please do the following steps in Eclipse IDE(Tested with Version: 3.5.2),
In Package Explorer, Right Click on the Project which integrated with Maven container.
Select Maven 2 and then select "Fetch Source JARs".
The above action wil fetch sources of all the 3rd party jars present in the Maven Classpath.
Regards,
Rajesh.
Just put the .m2/repository/ folder itself with the search subfolders option.