使用 Groovy 插件将原始 .groovy 文件添加到 Eclipse 中的输出目录
我正在使用 Eclipse 并且安装了 Groovy 插件。
在标准 Java 项目中,我想在运行时类路径上包含一个扩展名为 .groovy 的文件。我有一个源文件夹(src/main/resources),其中包含所有文件并且没有排除过滤器。在该目录中我有 2 个文件:foo.groovy 和 foo.txt。当我从 eclipse 清理并重建项目并查看输出目录时,我看到 foo.txt,但找不到 foo.groovy。
有谁知道是否可以让 Eclipse 将具有 .groovy 扩展名的文件像任何其他资源文件一样处理,同时仍然安装 Groovy 插件并在同一工作区中拥有其他 Groovy 项目?
如果您想知道,我正在尝试使用 groovy 脚本配置 logback。如果还有其他方法可以实现此目的,请告诉我。
I'm using Eclipse and I have the Groovy Plugin installed.
From within a standard Java project I want to include a file with a .groovy extension on the runtime classpath. I have a source folder (src/main/resources) which includes all files and has no exclusion filters. Inside that directory I have 2 files: foo.groovy and foo.txt. When I clean and rebuild the project from eclipse and look in the output directory I see foo.txt, but foo.groovy is nowhere to be found.
Does anyone know if it's possible to have Eclipse treat a file with a .groovy extension like any other resource file while still having the Groovy plugin installed and having other Groovy projects in the same workspace?
In case you are wondering, I'm trying to get logback configured using a groovy script. If there's some other way to accomplish this please let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Groovy-Eclipse 2.1.0 中有一个新功能,允许您指定脚本文件夹。这些文件夹包含未编译的 groovy 文件,可以选择将其复制到输出文件夹。 src/main/resources 默认是一个脚本文件夹。
要启用此功能,请安装 2.1.0(或更高版本)并转到首选项 ->格罗维 ->编译器。
There is a new feature in Groovy-Eclipse 2.1.0 that allows you to specify script folders. These folders contain groovy files that are not compiled and are optionally copied to the output folder. src/main/resources is a script folder by default.
To enable this, install 2.1.0 (or later) and go to preferences -> Groovy -> compiler.
几年前我也遇到过同样的事情。 Groovy 插件将 .groovy 文件视为源文件。同样,.java 文件不会放入输出目录,.groovy 文件也不会放入输出目录。当时我找不到解决这个问题的方法。我不知道是否有解决办法,但我确实想出了一个解决方法。
我将扩展名 .g 用于 groovy 文件,我想将其保留为脚本并在运行时解释它们。这些将被 groovy 编译器跳过并最终出现在输出目录中。通过这种方式,您还可以混合编译的 groovy (.groovy) 和运行时解释的 groovy 文件 (.g)。
** 编辑 **
请参阅@Andrew Eisenberg 的评论。最初提出这个问题时,这个答案是正确的。他的答案是正确的,因为有新版本的 eclipse 插件。
I ran into the same thing a few years ago. The Groovy plugin treats .groovy files as source files. The same way a .java files do not get put into the output directory, neither do .groovy files. At the time I could not find a way around this. I don't know if there is a way around it but I did come up with a workaround.
I used the extension .g for groovy files that I wanted to keep as scripts and have them interpreted at runtime. These would be skipped by the groovy compiler and would end up in the output directory. Also doing things this way allows you to mix compiled groovy (.groovy) and runtime interpreted groovy files (.g).
** EDIT **
See comment from @Andrew Eisenberg. This answer was correct when this question was originally asked. His answer is correct going forward since there is a new version of the eclipse plugin.