如何在Eclipse项目中构建期间过滤资源? [英] How to filter ressources during build in Eclipse project?

查看:172
本文介绍了如何在Eclipse项目中构建期间过滤资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序使用多个配置文件(只需在这里考虑appli.properties)。
这些文件包含几个取决于环境的值。我们可以找到一些信息,例如:

  server.port = $ {envi.server.port} 

另一方面,我有一组属性文件,每个环境一个(dev.properties,homolo.properties等) 。
它们包含配置文件中某些属性的值。我们可以在这里找到这种属性:

  envi.server.port = 4242 

我的构建由Maven2处理。一切都正常。



然而,我现在需要将我的项目导入Eclipse。
我主要关心的是配置文件过滤。的确,如果我的项目的Eclipse参数中没有修改任何东西(在一个 mvn eclipse:eclipse命令之后),那么我所有的配置文件将保留属性密钥(即 $ {envi.server.port} )而不是它们的值。有了这样的配置文件,我的应用程序将不会在Eclipse中运行...



所以我尝试了两个解决方案:





这两个解决方案的常见问题是过滤是在每个操作(基本上保存在Java类版本上),然后花时间。第二个解决方案比第一个解决方案要快(3秒)(超过10秒)。



你觉得我的方法是什么?
你会如何以更好的方式这样做?

解决方案

如果资源没有经常改变,你可以将Maven构建只能在Clean构建之后运行,那么它不会干扰太多,这不会加快构建速度。



就像过滤更快一些,我不知道有什么其他简单的机制可以帮助你,因为你已经说过你需要Ant或者Maven来运行过滤,而且他们都需要一些时间才能建立起来,导致速度减慢。



如果这会导致很多问题,您可以编写一个自定义的增量Eclipse构建器,它们对三角形执行过滤。这应该是相当快的,但显然要写更多的努力。


I have an application that uses several configuration files (let just consider appli.properties here). These files contain several values that depend on the environment. We can find some information such as:

server.port=${envi.server.port}

On other side, I have a set of properties files, one per environment (dev.properties, homolo.properties, etc.). They contain the values for some properties in configuration files. We can find here this kind of properties:

envi.server.port=4242

My build is handled by Maven2. Everything is working fine.

However, I now need to import my project into Eclipse. My main concern is about the configuration files filtering. Indeed, if I do not modify anything in my Eclipse parameter for my project (after a mvn eclipse:eclipse command), then all my configuration file will keep the property keys (i.e. ${envi.server.port}) instead of their values. And with such configuration files, my application will not run inside Eclipse...

So I tried two solutions:

  • A full-Maven solution, using m2eclipse plugin. I add a Maven Builder in the project configuration, and then, each time a build is made, the filtering is done on the files.
  • Ant (which is only used inside Eclipse). I've hardly defined a task that simulates the Maven2 filtering of files in Ant. This task is only dedicated to the filtering, no compilation.

The common problem of these two solutions is that the filtering is made at every operation (essentially saves on Java class edition), and then take time. The second solution is however quicker (3 seconds) than the first one (more than 10 seconds).

What do you think of my approach? How would you do that, in a better way?

解决方案

If the resources are not changed that often, you can set the Maven build to only run after a Clean build, then it won't interfere so much, this doesn't do anything to speed up the build however.

As far as making the filtering quicker, I don't know of any other simple mechanism that will help, as you've said you need either Ant or Maven to run the filtering, and they both take some time to set up before building, resulting in the slow down.

If this is causing you a lot of problems, you can write a custom Incremental Eclipse builder that performs the filtering on the deltas. This should be considerably quicker, but obviously a lot more effort to write.

这篇关于如何在Eclipse项目中构建期间过滤资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆