开发者

groovy eclipse and scripts that aren't classes

开发者 https://www.devze.com 2023-03-08 19:51 出处:网络
The groovy eclipse tutorial launches off in the direction of making a class. If I j开发者_运维知识库ust want to make a script, what do I do? Just make a file in some folder that is named \'something.

The groovy eclipse tutorial launches off in the direction of making a class.

If I j开发者_运维知识库ust want to make a script, what do I do? Just make a file in some folder that is named 'something.groovy' and expect eclipse to be willing to run it?


In the new Groovy Class Wizard, there is a checkbox to create a script instead of a class:

groovy eclipse and scripts that aren't classes

Alternatively, you can create a regular class and delete all the contents except for the package statement. That is a script.

A couple of points, though. The script should be in a source folder with a proper package statement if not in the default package. If not, you will not have any editing support for your script.


I'm not familiar with the groovy plugin for eclipse but there should be no problem creating a simple groovy script and running it from Command line or from Eclipse.

Save the following as hello.groovy somewhere:

System.out.println("Hello Groovy");

Create a Java run configuration it with the groovy jar in the classpath and main method is in groovy.lang.GroovyShell. Pass the script name as an argument (You can use ${resource_loc}) to make it a generic run configuration and it will work fine.

Edit: You can also find instructions on running groovy scripts on the Groovy website

0

精彩评论

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