Ideal怎么搭建Groovy

安装Groovy

验证是否成功:

# groovy -version
Groovy Version: 2.3.6 JVM: 1.7.0_67 Vendor: Oracle Corporation OS: Linux

打开groovyConsole:

Ideal怎么搭建Groovy

 

4)、使用IDE进行开发(这里以Intellij idea 13.1为例)

1. Enable the plugin

Before you create your first Groovy application make sure Groovy plugin is enabled in Settings → Plugins.

Ideal怎么搭建Groovy

2. Create a new project

Open Project Wizard and select Scala template. Since Groovy requires Java you have to specify the Project SDK.

Ideal怎么搭建Groovy

If you create a Groovy project for the first time IntelliJ IDEA will offer you to create Groovy SDK library. Press Create button and choose directory with a Groovy SDK.

Ideal怎么搭建Groovy

The IDE will create an empty project.

Ideal怎么搭建Groovy

3. Create a new class

The easiest way to create Groovy class or script is to use Ctrl + N shortcut from Project View or Navigation Bar.

Ideal怎么搭建Groovy

Choose between class, interface, enum and annotation with Up and Down arrows.

Ideal怎么搭建Groovy

Let's create a class with a method returning 'Hello, world!' string.

Ideal怎么搭建Groovy

4. Create a new script

Now we can create a script file via Ctrl + N shortcut.

Ideal怎么搭建Groovy

Choose between script and GroovyDSL script with Up and Down arrows.

Ideal怎么搭建Groovy

Now we can create an instance of our class and invoke hello method.

5. Run the project

In order to run the application you can manually create a Run configuration via Run → Edit configurations or run the active script automatically by pressing Ctrl + Shift + F10 shortcut.

Ideal怎么搭建Groovy

 使用Groovy Shell :

打开Tools-->Groovy Shell...

Ideal怎么搭建Groovy

使用Groovy Console :

打开Tools-->Groovy Console...

Ideal怎么搭建Groovy