Sunday, February 9, 2014

I have a Maven project with JavaScript code. There is a special javascript compiler plugin connected to the compile goal in the pom.xml. So when I type "mvn compile" then the JavaScript sources in src/main/javascript are compiled (compressed and obfuscated) and saved into the target/classes directory. On the command line this works great.
But now I want to make the development easier by using Eclipse with the m2eclipse plugin. I want Eclipse to call the compile goal whenever I change a JavaScript file. How can I do this? When I save a JavaScript file then I just see a "AUTO_BUILD" logging line in the maven console and that's it.
In the project preferences it is possible to configure a lifecycle mapping. But for some reason I can only add custom goals to "after clean" and "on resource changed". When I add the "compile" goal to the "resource changed" lifecycle mapping, then the JavaScript files are compiled when I change a resource. So I could put my JavaScript files into the resources folder instead and it would work but this sounds pretty ugly.
It is also working when I tell Eclipse to "clean" my project. Then the compile goal target is called. So the functionality is all there I just want to have it executed when I save a JavaScript file. This must be possible somehow, or not?
Any hints?
share|improve this question
add comment
In the project preferences it is possible to configure a lifecycle mapping. But for some reason I can only add custom goals to "after clean" and "on resource changed". When I add the "compile" goal to the "resource changed" lifecycle mapping, then the JavaScript files are compiled when I change a resource. So I could put my JavaScript files into the resources folder instead and it would work but this sounds pretty ugly.
As you've noticed, the default goals run on incremental builds in Eclipse are process-resources andresources:testResources. Personally, I don't find ugly to put js file under resources and I would just bind the javascript plugin on process-resources.
It is also working when I tell Eclipse to "clean" my project. Then the compile goal target is called.
On full build (after a clean from Eclipse), goals run are process-test-resources which is actually a build lifecycle phase that includes the compile phase, that's why compile get called when you clean your project from Eclipse. But this doesn't solve your issue (running your plugin on save).

As I said, I would just put the js file under resources. But there is maybe another option: adding another Builder to the project. Right-click on your project, then Properties > Builders > New > Maven Buildand define your plugin goal as goal to run during Auto Build Goals (change or remove the other goals to suit your needs):
alt text
But I prefer the other approach.
share|improve this answer
13 
Do not have this builder available in the New-Builder wizard (in my particular setup of Helios + m2eclipse). How did you do that? –  Jörg Feb 14 '11 at 12:12
1 
Same. No maven builder, though I have m2e installed. –  Travis Webb Aug 21 '12 at 16:50
2 
m2e must have changed in the last two years. –  antony.trupe Dec 17 '12 at 17:18
2 
@antony.trupe True. I cannot follow these instructions either. –  Ludwig Magnusson Jan 11 '13 at 10:40
 
it seems to me functionality changed because of this: wiki.eclipse.org/M2E_plugin_execution_not_covered ; I find something similar in right click project -> run as -> run configurations where you can configure any maven goal. But it doesn't bind to the specific project build lifecycle. –  akostadinov Feb 28 '13 at 21:15
add comment

No comments: