开发者

Add raw .groovy file to output dir in Eclipse with Groovy Plugin

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 .g开发者_运维百科roovy 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜