Eclipse+Maven compile problem - eclipse

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.

Related

Using maven generated sources in 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

Working with a Scalatra application in an Eclipse workspace? (i.e. build path)

I am experimenting with a small Scalatra web application, which I have imported as a project into Eclipse.
I have used Eclipse to manage a few Lift applications before. With a Lift project, SBT copies all the dependency JAR's to a /lib_managed directory. I can therefore add those JAR's to Eclipse's build path, and it co-exists with SBT just fine without complaining about missing classes.
With Scalatra, however, the dependency JAR's don't seem to get copied anywhere helpful during the development cycle. If you build a WAR file, then the dependencies get bundled up into that... but there doesn't seem to be anything like Lift's /lib-managed directory.
Assuming that anyone else uses Eclipse in developing Scalatra projects, how might I easily set up Eclipse's build path? I suppose that I could manually create entries that point my local Ivy repository one-by-one, although that seems a bit ugly. Perhaps there's an easy way through SBT to setup something similar to Lift's /lib-managed subdirectory inside the project directory.
It looks like the best approach for this is using the SBT plugin for Eclipse.
This is not an "Eclipse plugin" for managing SBT. Rather, it's an "SBT plugin", for generating the .project and .classpath files used by Eclipse. The Maven world used to deal with Eclipse in a similar manner, before the m2eclipse Eclipse plugin reached maturity over the past couple years.
With this plugin installed (I installed it globally so I wouldn't have to change my project's files), you just type sbt eclipse after any changes to your dependencies. SBT will then update your Eclipse project files to match.
You could also use my Maven prototype, then simply import the maven project into Eclipse. Quite nice and you're not forced to use SBT.
https://github.com/fancellu/scalatra-maven-prototype

OSGi bundles dependency management in Eclipse

I have an OSGi bundle which is in Eclipse IDE represented as Eclipse Plug-in Project. The only way I found to satisfy the dependencies of this plug-in/bundle is to
1) import all dependencies (.jar files) through File > Import... > Plug-ins and Fragments wizard
2) and then declare the imported dependencies in MANIFEST.MF
Yes, this solution works, but on the other hand after I commit the changes to our repository all my team mates also have to manually import dependencies to Eclipse to fix the compilation errors.
QUESTION:
Is there a solution which does not require such irritating steps? I just want to pull the changes from repository and continue my work without need to fix the dependecies in MANIFEST.MF again and again...
P.S.: To retrieve dependencies we use Apache Ivy.
You need to set up a target platform in Eclipse. I find the easiest way is to put all the dependencies in a folder, and save the target platform as a .target file which I check into source control. Then the only steps my colleagues need to do is retrieve the dependencies and configure Eclipse to use the shared target definition. If we add new dependencies to the definition Eclipse will automatically pick up the changes with a restart or target platform refresh.
The Eclipse documentation should get you started: http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.pde.doc.user/concepts/target.htm
If you develop server based applications then it is much better to let maven or Ivy manage the dependencies and use the maven bundle plugin to generate the Manifest. So you can avoid the Eclipse OSGi mode and the target platform. See http://www.liquid-reality.de/x/DIBZ for a tutorial how to develop OSGi bundles using maven and deploy on Apache Karaf. For Ivy you may have to use a slightly different build but the basics should be the same.

Eclipse and Ant integration

Is there a way for my eclipse project to inherit the build classpath from existing Ant build.xml files? It would be nice if I didn't have to keep the eclipse project and the ant build in sync!
Off-hand, I'd say no, but see here http://www.ant4eclipse.org/node/6 for an attempt at doing the opposite (keeping the Ant build path in sync with Eclipse). Maybe that's of some use?
Another option would be is for both ant and eclipse to point to a common file specifying dependencies, independent from both ant and eclipse.
You can do this with ivy (http://ant.apache.org/ivy/), which has both tasks for ant and a eclipse ide plugin. ivy also solves the third-party library dependency management problem (you create a central repository of all third-party dependencies in your company which are pulled down as needed, rather than keeping .jar files with each project).
It takes a little time to create the initial ivy repository by copying libraries from maven, but is well worth it longer-term.

m2eclipse and Eclipse WTP

I have a very large workspace with about 30 projects all together. I am using Eclipse 3.5 with m2eclipse. I check out of my subversion repository using the defaults in order to import the projects into my workspace.
I create a Tomcat server instance, and publish my web project to the tomcat server. Sounds easy enough.
The problem is that it does not appear as though the transitive dependencies for my other projects are being automatically added to the container, so when the container starts up I get classnotfound exceptions, etc.
I go into the web project's properties, and I notice that the Java EE Module Dependencies are NOT checked for some of the transitive dependencies. I check them, and everything seemingly works until I do a project clean build, when the Java EE Module Dependencies are automatically reset by eclipse, so I need to recheck them. This is maddening, and I was hoping there was some way to automatically pull in all of the transitive dependencies when working with Eclipse WTP.
I should mention, using standard maven build works just fine, and everything gets pulled in appropriately into the resulting WAR file. It just doesn't work so good with WTP for some reason.
You need to make sure that you have "Maven integration for WTP" feature from m2eclipse installed. There is a simple tutorial available at http://docs.sonatype.org/display/M2ECLIPSE/WTP+mini+howto
What version of WTP and m2eclipse you are using? Check that dependency version declared in project's pom.xml matches with version declared in workspace project and make sure that workspace dependency resolution is enabled.
Also, you can try to run "Maven / Update project configuration" from the project popup menu and check that there is no errors on Maven console and in Eclipse's own log.
If the above won't help, try to reproduce issue on a smaller project and then submit it with a bug report
It appears as though the latest version of m2eclipse (.99x) solves all of my issues.
If you are tempted to use m2eclipse wtp extras you need to be aware that they are not supported by Sonatype and, although mostly OK, are not 100% robust.
See http://maven.40175.n5.nabble.com/What-is-the-recommended-alternative-to-m2eclipse-extras-WTP-integration-td135727.html