Whats the right way to get my maven projects into Eclipse?

3,794 views
Skip to first unread message

Alex Black

unread,
Oct 27, 2010, 9:21:37 AM10/27/10
to Scala IDE User
In 2.7.7, I used mvn eclipse:eclipse to generate .project files, and
then in Eclipse I imported those 'existing' eclipse projects.

Is this the right approach for 2.8? I'm using Scala (and IDE) 2.8.0
final, Eclipse 3.5.2, and I have m2eclipse installed.

I noticed my .project files now have *two build* and *two scala
natures*, so I then rebuilt my .project files with "mvn
eclipse:eclipse", and they now have a warning:

<comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-
eclipse-plugin are not supported in M2Eclipse.</comment>

Here is the problem .project file with two build commands and two
scala natures:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>cs</name>
<comment></comment>
<projects>
<project>dataStore</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.scala-ide.sdt.core.scalabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.scala-ide.sdt.core.scalanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>ch.epfl.lamp.sdt.core.scalanature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

Alex Black

unread,
Oct 27, 2010, 9:39:56 AM10/27/10
to Scala IDE User
I found this page:

https://www.assembla.com/wiki/show/scala-ide/With_M2Eclipse

It says to import existing maven projects, which worked for me. I
deleted my existing .project files, then imported my two projects as
existing maven projects, and got .project files with 2 build commands
but just 1 scala nature:

Does this look right?

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>dataStore</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.scala-ide.sdt.core.scalabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.scala-ide.sdt.core.scalanature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>

David Bernard

unread,
Oct 27, 2010, 9:45:29 AM10/27/10
to scala-i...@googlegroups.com
yes

Alex Black

unread,
Oct 27, 2010, 10:25:53 AM10/27/10
to Scala IDE User
thx

Ichthyostega..

unread,
Oct 27, 2010, 1:22:40 PM10/27/10
to scala-i...@googlegroups.com
Am 27.10.2010 15:21, schrieb Alex Black:
> In 2.7.7, I used mvn eclipse:eclipse to generate .project files, and then in
> Eclipse I imported those 'existing' eclipse projects.
>
> Is this the right approach for 2.8?  I'm using Scala (and IDE) 2.8.0 final,
> Eclipse 3.5.2, and I have m2eclipse installed.
>
> I noticed my .project files now have *two build* and *two scala natures*,


Hi Alex,

that exactly is the kind of problems which finally drove us to stop
using the M2-ECLIPSE. "We" here means a team developing several medium
sized J2EE projects in the banking environment. Our build process contains
nothing really fancy, but I'd label it "real world enterprise grade",
definitively not a toy project. We have a mix of several JVM languages
(but the core is in plain java) plus Spring plus some MBeans, packaging
for JBoss plus AspectJ for integrative concerns.

The summary is: in the current stage of development, M2-Eclipse simply
isn't up to the job. It is buggy, non-transparent, incompletely implemented
when it comes to things like AspectJ, yet does magic things and in the result
messes up a correct project configuration often without any obvious reason.
To add to this mess, it considerably slows down Eclipse.

While many of these things could be worked out (by reporting bugs and
providing test cases), the most serious problem is that M2 creates and
manages a "maven classpath container" for your dependencies, and the
details of this are kept opaque. We've found no possibility reliably
to control the behaviour of this plugin, which is a must in our setup:
We have the hard requirement that any build must be reproducible
entirely on the commandline and must not depend on an IDE configuration.

Thus we've gone through the pain of configuring all our projects for
the maven-eclipse-plugin. That is a bit of manual work, but not really
hard, because maven-eclipse-plugin is mature and works predictably.
The downside is that now we have to do a mvn eclipse:clean eclipse:eclipse
after changing some library dependencies, but the performance gain when
using the eclipse workbench without M2 was significant.

Btw, it is possible to still to have the M2 plugin installed (some of
our developers work this way). This gives you the POM editor and the
possibility to launch a maven commandline build from within the IDE.
But the important point is to import the generated Eclipse projects
just as "Import> Existing projects into Workspace" and not as
"Import> Maven Projects". That is, we don't have the maven project
nature and thus disable any magic done by the M2-plugin.


> <comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-
> eclipse-plugin are not supported in M2Eclipse.</comment>

So this warning just tells you that you can use only one of the two,
not both in conjection. Either let maven-eclipse-plugin write a
complete Eclipse project configuration, which is then used within
Eclipse *unaltered*, or just use the M2 plugin on a bare project
to figure out magically what dependencies to add. But not both.

Cheers,
Hermann Vosseler

Alex Black

unread,
Oct 28, 2010, 10:57:36 AM10/28/10
to Scala IDE User
Hi Hermann, thanks for all the info.

Can you tell me a bit more about whats involved to run Eclipse and
Maven without using M2? Is it just a matter of running mvn
eclipse:eclipse for each project?

- Alex

Ichthyostega

unread,
Oct 28, 2010, 7:23:40 PM10/28/10
to scala-i...@googlegroups.com
Alex Black schrieb:

> Can you tell me a bit more about whats involved to run Eclipse and Maven
> without using M2? Is it just a matter of running mvn eclipse:eclipse for
> each project?


Hi Alex

short answer: yes, that's all for everyday use.

long answer: depending on your circumstances, it might be necessary
to tweak the parameters of the maven-eclipse-plugin a bit, so the
generated .project and .classpath files yield the desired results.

As you can see from the documentation
http://maven.apache.org/plugins/maven-eclipse-plugin/eclipse-mojo.html
...this plugin has a lot of flexible options.
For example, we're using the <additionalConfig> to roll out a basic set
of compiler waring settings, code formatter, code cleanup and similar
options to the whole team as a starting point for the individual
developer to play with.


Then, when setting up a new workspace (maybe after the initial checkout
from SCM) it is advisable to do a complete build at the commandline
(mvn package or mvn install) and then mvn eclipse:clean eclipse:eclipse

After that do a "Import> existing projects into workspace"

(note: *not* import maven projects)

In everyday use, whenever some new lib dependency got added/changed/
removed from POM, just run mvn eclipse:clean eclipse:eclipse. If you
have a multi module maven project setup, you can run it from the
root project and thus get it executed in every module. While on first
use, the eclipse:eclipse goal requires quite some time, because of
downloading javadoc and sources of the libraries, later re-running
these goals requires just some seconds.
It is a good idea to "disable" Eclipse somehow during that run, so it
can't barf when it detects the (old) .project file(s) are gone. Either
close the projects or (even simpler) just suspense the whole Eclipse
process with the task manager of your OS.

As said, you can still have the M2 plugin installed. Just be sure that
you don't have a maven nature on your projects. (You can enable/disable
the maven nature by right clicking on the project top level and then
there is some option "enable dependency management" (just quoting from
my memory here)

hope that helps,
Hermann

PS: I didn't mention Scala, because it just behaves as expected!
The nice thing is, you can even "sneak in" Scala this way, because
the individual developer on a larger team doesn't need to install
the compiler manually. Just running mvn clean package eclipse:eclipse
gives you a complete Scala install, and with mvn scala:console you even
get a console to play with your code, all your specific modules already
added to the classpath (I especially love this feature)

Besides, you can use the "jar-with-dependencies" packaging provided by
maven, to create a self contained jar, including the scala runtime, which
can just be executed on any JRE with "java -jar path/to/your.jar"

David Bernard

unread,
Oct 29, 2010, 9:20:15 AM10/29/10
to scala-i...@googlegroups.com
using maven-eclipse-plugin require more human actions :
* more configuration into pom.xml (see scala-ide wiki)
* call "mvn eclipse:clean eclipse:eclipse" after pom.xml modification
* explicit refesh of project after call of "mvn eclipse:clean
eclipse:eclipse" (I suggest to create a eclipse external tools to do
the stuff : use variable like ${project:location} and force refresh)
* calling the plugin from a parent directory or a modules directory
(in multi-modules) could generate difference (at least with the
version I used 2 year ago)

Some version of maven-eclipse-plugin are very buggy => set version of
the plugin in you pom.xml

IMHO, m2eclipse is more user friendly than maven-eclipse-plugin for
scala project.

If someone has suggestion, tips,.. don't forgot to update the wiki
pages under https://www.assembla.com/wiki/show/scala-ide/Using_Maven_with_the_Scala_IDE_for_Eclipse

/davidB

Ichthyostega

unread,
Oct 30, 2010, 4:44:20 PM10/30/10
to scala-i...@googlegroups.com
David Bernard schrieb:

> IMHO, m2eclipse is more user friendly than maven-eclipse-plugin for scala
> project.

sorry you're missing the point. It might well be that M2 planned to be
"user friendly" or even give a "user experience". But I'm a professional
software devloper and just need software that works, isn't buggy, is
controllable and doesn't magical stuff.

In its current state M2 falls short on all of these concerns,
thus it can't be recommended for serious work. Hopefully the M2 people
nail out that problems, and maybe next year we've got a version that
works and even has "user experience" ;-)

Hermann

hedefalk

unread,
Nov 4, 2010, 10:19:30 AM11/4/10
to Scala IDE User
When you use maven-eclipse-plugin for a multi module project, how do
you catch updates to the dependencies? Have you manually setup the
same dependencies that are declared in the pom.xml in Eclipse or is
this done automatically? What I mean is the following:

If I split up a project with two artifacts like

myproject-model
myproject-gui

where myproject-gui depends on myproject-model, I like changes on
myproject-model to be picked up instantly in myproject-gui with
Eclipse's continuous compilation. I get this for free with m2eclipse,
but if I only do mvn eclipse:eclipse I guess I would have to either
run mvn install on myproject-model for this to be picked up in
myproject-gui or I would have to setup an extra dependency manually in
Eclipse. Or is this handled by the maven-eclipse-plugin also in some
magical way?

Cheers,
Viktor

hedefalk

unread,
Nov 5, 2010, 9:48:29 AM11/5/10
to Scala IDE User
When using the maven-eclipse-plugin, are changes to a dependency
within you Eclipse workspace automatically picked up in the classpath
of the "dependee"? What I mean is this:

Say I have a project in two modules:

myproject-model
myproject-gui

where myproject-gui depends on myproject-model.

If I make a change in a class of myproject-model, will this
immediately be picked up in the classpath of myproject-gui? With
m2eclipse I get this behavior so Eclipse's incremental build of
myproject-model will immediately be propagated to myproject-gui and
this is for me a necessity since I normally split up my projects in
many small modules. If I understand how maven-eclipse-plugin work this
will probably only add entries in .classpath for the dependencies in
the maven-repo so I would either have to do mvn install on myproject-
model or I would need to manually change the dependencies to be
project-dependencies within the workspace. The later I would consider
a much bigger side-step of the normal maven build than anything
m2eclipse does.

Maybe maven-eclipse-plugin fixes this too somehow? Am I missing
something?

Ichthyostega

unread,
Nov 6, 2010, 8:11:03 PM11/6/10
to scala-i...@googlegroups.com
hedefalk schrieb:

> When using the maven-eclipse-plugin, are changes to a dependency within you
> Eclipse workspace automatically picked up in the classpath of the "dependee"?
> If I make a change in a class of myproject-model, will this immediately be
> picked up in the classpath of myproject-gui?

yes, because the maven-eclipse-plugin creates the individual modules
as "depndent projects" in eclipse. I.e. you see the prerequisite
projects on the "build path" tab in the project configuration.

When you use incremental compilation, changes e.g on library classes
automatically propagate through the workspace as you'd expect

The only (and key) difference is when it comes to *altering* your
project configuration in eclipse.
* maven-eclipse-plugin *never* does anything autmagically here
and never changes anything without being explicitly invoked
* M2 tries to do things much more automatically, which might
include even changing project dependencies at points where
you might not expect it.


Please get me right: it seems that M2 can become the tooling we
all desire eventually, i.e. it would relieve us from caring about
a lot of tedious details -- just it isn't there right now and I
wouldn't recommend to rely on it in any production environment.


> When you use maven-eclipse-plugin for a multi module project, how do you
> catch updates to the dependencies?

In a multi module project, usually you'd use some kind of "parent POM"
on which all the individual modules depend. You're not forced to do
it this way, but its good advice when you start using -- well let's say
"more than 3 modules".

In that case, the parent pom would declare the libraries you depend on
explicitly (with version), probably using some properties to control
repeately re-used version numbers (like e.g. the version of Hibernate,
spring or similar) individual modules then just pull in the dependencies
they need, without version number. Same for the plugins, where most common
configuration would reside in the parent pom

With such a setup, when you change a library version number in the
parent pom (or add a new lib dependency), then you'd just execute
mvn eclipse:clean eclipse:eclipse *from the parent project*. This
propagates to the individual projects and thus re-generates all
eclipse project files with the new dependencies set explicitly.
This requires just some seconds; the only downside is that
you need to trigger it manually...


Cheers,
Hermann


Reply all
Reply to author
Forward
0 new messages