且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何启动Maven“编译”保存在Eclipse中的目标?

更新时间:2023-09-17 21:04:10

blockquote>

在项目首选项中,可以配置生命周期映射。但是由于某种原因,我只能将自定义目标添加到清理和更改资源之后。当我将编译目标添加到资源更改生命周期映射中时,当我更改资源时,会编译JavaScript文件。所以我可以将我的JavaScript文件放在资源文件夹中,它会工作,但这听起来很丑陋。


正如你所注意到的,在Eclipse中的增量版本中运行的默认目标是 process-resources resources:testResources 。就个人而言,我没有发现丑的将js文件放在资源下,我只需要绑定 process-resources 上的javascript插件。


当我告诉Eclipse清理我的项目时,它也正常工作。然后,编译目标目标被调用。


在完整构建(从Eclipse清理之后),运行的目标是 process-test-resources 这实际上是一个构建生命周期阶段,包括 compile 阶段,这就是为什么 compile 被调用。但是这并不能解决你的问题(在保存中运行你的插件)。






正如我所说,资源下的js文件。但也许有另一个选择:将另一个Builder添加到项目中。 右键单击项目,然后单击属性>构建器>新建> Maven构建,并将您的插件目标定义为在自动构建目标期间运行的目标(更改或删除其他目标以满足您的需要):



alt text http://img694.imageshack.us/img694/2382/screenshot003wo.png



但我更喜欢其他方法。


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?

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 and resources: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 Build and define your plugin goal as goal to run during Auto Build Goals (change or remove the other goals to suit your needs):

alt text http://img694.imageshack.us/img694/2382/screenshot003wo.png

But I prefer the other approach.