在 Eclipse 中运行 groovy 脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4594030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 19:50:50  来源:igfitidea点击:

Running a groovy script in eclipse

eclipsegroovy

提问by Leikingo

I'm currently writing some groovy scripts. Till now I simply use notepad and run the scripts via groovy script.groovy. But I'm looking some help for editing the files. So I tried eclipse with the groovy plugin which looks great...for groovy projects. But I just want to edit and run the groovy scripts. No Project dir etc.. What's the best way to handle scripts in eclipse. I don't want to package the files to jars or something like that. I have just a folder with some scripts in it... No src/bin directory or subfolders for package names. Is that possible?

我目前正在编写一些 groovy 脚本。到目前为止,我只是使用记事本并通过groovy script.groovy. 但我正在寻找一些编辑文件的帮助。所以我用看起来很棒的 groovy 插件尝试了 eclipse...对于 groovy 项目。但我只想编辑和运行 groovy 脚本。没有项目目录等。在 Eclipse 中处理脚本的最佳方法是什么。我不想将文件打包成 jars 或类似的东西。我只有一个包含一些脚本的文件夹...没有 src/bin 目录或包名称的子文件夹。那可能吗?

Thanks, Ingo

谢谢,英戈

采纳答案by Sean Patrick Floyd

You must convert your project to a Groovy project (right-click project: Configure > Convert to Groovy Project), but then, sure, it's possible.

您必须将您的项目转换为 Groovy 项目(右键单击项目:)Configure > Convert to Groovy Project,但是,当然,这是可能的。

When editing a .groovyfile, select Run > Run as ... > Groovy Script

编辑.groovy文件时,选择Run > Run as ... > Groovy Script

回答by Dónal

It sounds like Eclipse is a bit heavyweight for your needs, have you considered using the GroovyConsole instead? It's a very simple Groovy IDE, available in the Groovy bindirectory. Assuming you have this directory on your PATH, you can start it by running groovyConsolefrom the command line.

听起来 Eclipse 对您的需求来说有点重量级,您是否考虑过使用 GroovyConsole 代替?这是一个非常简单的 Groovy IDE,可在 Groovybin目录中找到。假设你有这个目录PATH,你可以通过groovyConsole从命令行运行来启动它。

Useful shortcuts are:

有用的快捷键是:

  • Ctrl + R : run the script
  • Ctrl + W : clear the output
  • Ctrl + R :运行脚本
  • Ctrl + W :清除输出

回答by Steve

This solution still requires a "project", but aims to use Eclipse to do it in the least invasive way.

这个解决方案仍然需要一个“项目”,但旨在使用 Eclipse 以最小侵入性的方式来完成它。

http://andrewclement.blogspot.com/2009/12/using-eclipse-to-edit-your-groovy.html#!/2009/12/using-eclipse-to-edit-your-groovy.html

http://andrewclement.blogspot.com/2009/12/using-eclipse-to-edit-your-groovy.html#!/2009/12/using-eclipse-to-edit-your-groovy.html

Then you can use the "run as" as stated by Mr. Floyd :D

然后你可以使用弗洛伊德先生所说的“运行方式”:D