如何建立在Eclipse项目中筛选ressources? [英] How to filter ressources during build in Eclipse project?

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

问题描述

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

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}

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

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

我的构建是通过Maven2的处理。一切工作正常。

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

不过,我现在需要导入我的项目到Eclipse中。
我最关心的是关于配置文件过滤。事实上,如果我不修改我在Eclipse中的参数什么我的项目(​​后的 MVN日食:日食命令的),那么我所有的配置文件将保持属性键(即 $ {envi.server.port} ),而不是它们的值。而这样的配置文件,我的应用程序将无法在Eclipse中运行...

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:


  • 一个全Maven的解决方案,使用m2eclipse插件。我想补充一个Maven构建项目配置,然后,构建而成,在​​滤波上的文件进行。每次

  • 蚂蚁(这是只有在Eclipse中使用)。我有<一个href=\"http://stackoverflow.com/questions/1232532/simulating-the-maven2-filter-mechanism-using-ant\">hardly定义模拟文件的蚂蚁的Maven2的过滤任务。这个任务只有献身于过滤,没有编译。

  • 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.

这两种解决方案的共同问题是,滤波是在每一个操作(基本上节省Java类版)制成,然后取时间。第二溶液是但比第一个快(3秒)(10秒以上)。

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?

推荐答案

如果资源不改变,往往,你可以设置Maven构建只有一个干净的构建后运行,那么它不会干涉这么多,这什么都不做然而,加快打造。

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.

至于使过滤更快,我不知道任何其他简单的机制,这将有助于,正如你所说,你需要Ant或者Maven来运行过滤,他们都需要一些时间来建立之前建设,造成减速。

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.

如果这是你造成很多问题,你可以写一个自定义的增量Eclipse的执行对三角洲过滤建设者。这应该是相当快,但显然更多的努力来写。

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项目中筛选ressources?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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