Using maven generated sources in Eclipse - eclipse

I have an application made up of a number of maven projects. I work on it in Eclipse. Some of the projects use Maven plugins to generate stub classes for web services etc.
When i import the projects into a new workspace I have to issue a maven generate sources command followed by attach source folders to build path on each project. The application i work on has more than 5-6 projects which require these steps.
Is there a plugin I can install in Eclipse to pick up the generated sources, or even one that generates the sources and updates the build path to save the manual steps?

I'm pretty sure the m2e plugin takes care of this automatically. m2e is included in the primary Java and Java EE packages of recent Eclipse versions, so you probably already have it. If you right-click on your project, and there is a Maven submenu, then the project is already managed by m2e. Otherwise, right-click and choose Configure > Convert to Maven project.

Well, it depends on exact maven plugin you are using.
generate sources
Before I considered that m2e connector would be needed for any non common plugin, like generator. But I came recently on some plugins (1), that do it without special m2e connector.
attach source folders to build path
For this part check build-helper-maven-plugin and answer to M2E and having maven generated source folders as eclipse source folders

Related

Maven add source directory in Eclipse

I get my code generated from the maven-jaxb2-plugin maven plugin. It puts the code into target/generated-sources. Now I have to manually left click onto the project -> properties-> Java Build Path-> Add Folder.... That's kind of annoying for someone downloading it from SVN.
Is there some way to get that dome automatically through my pom?
This kind of stuff is the responsibility of IDE's Maven plugin and fortunately M2E supports it since recently (finally!) through the concept of M2E connectors, that is M2E extensions that understand a nature and lifecycle binding of certain plugins. And because it's since recently, not much Maven plugins have their connectors for M2E.
However, you're lucky, because Jaxb2 plugins are actually already supported. I assume you're already using M2E. Then go to Preferences -> Maven -> Discovery, then Open Catalog, then find Jaxb2 connector.
maven add-sources should do the trick for netbeans or eclipse
M2E and having maven generated source folders as eclipse source folders

How to clone Hibernate sources using Egit (Eclipse)?

I need help using Egit (Eclipse git integration capabilities). My goal is to have Hibernate sources in my local Eclipse. Eventually I aim for running their tests, doing some changes in the sources, issuing a git pull request (patch), etc.
Can someone explain how to clone Hibernate sources and have them as Java Project(s) in Eclipse?
All I can achieve myself is to have the sources cloned (as needed) to some specified path (the suggested path is outside of the workspace directory). Then I am puzzled trying to convert the structure into Java projects in Eclipse. I try different ways to import the project(s) using File | Import (e.g. Existing projects into workspace) or linking sources into a new created Java project. The problem seems to be the Hibernate sources are not a single maven project (not quite sure about this one either, I am new to maven) and probably not an Eclipse project at all, so Eclipse doesn't recognize the source structure at all.
It looks like it has both maven and ant builds, so you can generate Eclipse projects with both of these.
For maven you have 2 options:
Run mvn eclipse:eclipse to generate
eclipse project artifacts and then
import existing projects.
Install m2Eclipse and import Existing Maven
Project. This is the preferred
approach when working with Maven and
Eclipse.
For ant, New project->Java Project from Existing Ant Buildfile

How can I execute Maven goals from Eclipse without M2Eclipse?

I am using the eclipse plugin for maven to generate eclipse projects from maven pom.xml files.
mvn -Dwtpversion=1.5 eclipse:eclipse
This works fine and, after some experimenting with several of the 400 different archetypes available, I settled on using the webapp-javaee6 archetype, which was the only one which generated a set of dependencies that were both all available and which created a project that was useable by the WTP plugin.
The problem now is that I would like to be able to invoke mvn goals from eclipse. The accepted way to do this I understand is to use the m2eclipse plugin, which I have installed.
However, after playing around a bit and getting nowhere I discovered this comment in my .project file:
<comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
Further searching (see this lengthy diatribe from October) suggests I'm not (just) being stupid in not being able to get this to work.
The how-to linked in the top answer to this question seems hopelessly out of date.
So, the real question - what is currently the correct way to use maven to generate a WTP-friendly project that can be converted to eclipse and then use eclipse to call the project's goals?
Have you tried File -> Import -> Check out existing Maven Projects from SCM? My understanding is that m2eclipse will then create the eclipse project for you. If the packaging defined in the pom is war, the project should be deployable with WTP. (The latter used to require an the maven-wtp-integration plugin as well, don't know whether that's still the case).
Not sure about WTP or maven archetypes, but have you come across SpringSource Tool Suite (Spring packaged eclipse) and created a Spring Roo project? You can use this to create a data driven maven built web-app in a few mins. You can even remove the spring roo bits if you don't want them, it will give you a good starting point for a web-app with very little pain.

Eclipse Automatically Download / Update JAR files

I just created a Web App project from a repository through Eclipse's SVN support. What I would be doing is have an ANT build going and then finally deploy through Tomcat.
I am using Eclipse IDE for Java EE developers on an Ubuntu system.
There are a number of jar files needed
to support my project - like Struts,
Hibernate, etc. etc.
Do I need to
manually download each of them
and put them in the lib folder?
OR
Does Eclipse have a solution to
automatically UPDATE these from the internet? Any plugins to automatically take care of this?
You should consider using Maven for your project. It's VERY well supported in Eclipse, and handles all dependencies (as well as other things, such as releases).
The problem is there's a bit of a learning curve, but if you intend your project to get to a considerable size, I'd say it's very important.
Maven has support for ant builds and most libraries are in the central Maven repository. You just say your project has a dependency on the external project and it will automatically download the dependencies.
http://maven.apache.org/

Eclipse+Maven compile problem

currently, I am developing web-apps using Eclipse.
The build is done using Maven.
The problem is that during compile time Eclipse is showing a lot of errors since there are a lot of missing jars. The final result is OK since the Maven is responsible for fetching these jars.
How can make the eclipse not fail the compilation?
I know I can just add the missing jars to the project classpath, but that's not what I'm looking for because I have a lot of projects, and the .classpath file of each project is a file common to all developers, so I would rather not to change it.
My question is therefor, is there a way to add a common classpath to all Eclipse projects without changing each project's classpath?
I use m2eclipse. It adds a classpath container to the .classpath file. This container is populated with the Maven dependencies by a Maven builder (added to the .project when the Maven nature is enabled) which processes the POM and downloads any artifacts (and sources if needed).
To enable the Maven nature (assuming the plugin is installed), right-click on a project and select Enable Dependency Management.
By default m2eclipse uses an embedded version of Maven to do its processing. This typically means a separate local repository and duplicate files on the box. You can configure it to use your standard Maven installation in Window->Preferences->Maven->Installations. Then adding the path to your Maven installation (normally the same as M2_HOME).
There is another Maven plugin for Eclipse called IAM (formerly called Q4E). IAM is an Eclipse integration project and has some promising features - it's worth keeping an eye on.
There is a comparison of the Eclipse Maven integrations, alongside the maven-eclipse-plugin (a goal that generates the Eclipse metadata files from the POM contents). I personally find the maven-eclipse-plugin more trouble than it's worth but it may suit your purposes and it is handy for generating the initial metadata if you have none checked into the SCM.
Check out the m2eclipse plugin. It will read each project's POM and automatically fetch and add all dependencies to the classpath.