views:

42

answers:

2

Hi

I'm using Maven in Eclipse with the m2Eclipse plugin.

I'm very confused about how this is supposed to build within eclipse.

The on-the-fly compiling works as normal (i.e. as if without maven) so if you have an error it will be highlighted.

But when I want to run a junit for example, any changes to the code are only picked up after I run a maven build command. The Eclipse project clean doesn't seem to work.

Any help in explaining how this is all supposed to work would be greatly appreciated.

A: 

Checkout the http://m2eclipse.sonatype.org/ plugin documentation and guide.

Regards,

StudiousJoseph
Had a look through the doc but couldn't find the answer - if anyone can help would be really grateful.
Dan
+1  A: 

The eclipse builder uses simpler logic than maven, so sometimes the things m2eclipse does are just not enough. I usually keep a shell open to issue simple commands before I run unit tests. depending on your setup, here are some commands that might be helpful.

mvn process-resources
# This is usually enough when you have
# changed something in src/main/resources

If you know that the only resource processing needed is maven resource filtering, just call the goal:

mvn resources:resources

Same for tests:

mvn processs-test-resources

or

mvn resources:test-resources

If you need a fuller solution, because perhaps some new code has to be generated etc, then use

mvn test-compile
# This will through recursion process the following phases:

validate
initialize
generate-sources
process-sources
generate-resources
process-resources
compile
process-classes
generate-test-sources
process-test-sources
generate-test-resources
process-test-resources
test-compile

So you're getting pretty much everything except the actual unit test execution. Most plugins are smart enough to detect changes and leave unchanged files alone, so mvn test-compile is usually fast enough.

If you prefer not to use a shell, you can of course bind any of the above phases / goals to m2eclipse Run as... maven build targets.

seanizer