img

Groovy Script – A Guide to Learn Code Using Eclipse IDE

Eclipse is one the most commonly used IDE (Integrated Development Environment) by Java developers worldwide. Using an IDE greatly improves development effort. Eclipse does not natively support Groovy script but there are plugins available that can be used for this purpose. Some of major benefits of using an IDE include:

  • Code Completion
  • Syntax Checking
  • Refactoring
  • Highlighting
  • Integration with source control

Before we begin, let me clarify using an IDE is optional and we can always write the code directly into the Event Handler window and it will check for syntax and compile time errors for us. But this way, we won’t be able to make use of the features mentioned earlier.

INSTALLING GROOVY-ECLIPSE PLUGIN

First step is to download the Groovy plugin for eclipse.

The plugin we are going to use for this is Groovy-Eclipse available at:

Groovy Eclipse

URLs for releases of specific Eclipse are on the wiki page:

Copy the URL for version of Eclipse you have. Then launch Eclipse, click on Help and select Install New Software.

Paste the URL in the Work with and hit enter. Eclipse will pull the available installations.

For this case, we are going to install Groovy-Eclipse Feature and Groovy Compiler Feature.

Note: As of now Agile PLM supports Groovy 1.5.6 so any of the later compilers can work. The compiler feature for versions earlier than 1.8 is not available.

After making the selection, click next. Go through to the terms and conditions and hit finish to install.

Once installed, Eclipse will restart automatically.

On the New dialog, search for and select Groovy Project and then click Next.

Give the project a name and click finish.

Eclipse will create the Project for us. But before we can start writing code for our process extension, we have to include relevant libraries into our project.

The libraries we are going to need are the following. They come with the installation of Agile PLM.

  • AgileAPI.jar
  • agileclasses.jar

To do this, right click the Project and select Properties. In the Project Properties, select Java Build Path and go to Libraries tab. Click on Add External JARs and select AgileAPI.jar and agileclasses.jar. Click OK once done.

Now we are going to add a class for Groovy. To do that right click the src folder. Select New and Other.

In the New wizard search for and select Groovy Class and click Next.

In create new class window, enter a name for the package and class. Then click finish.

Eclipse will create the class. Edit it and add the following started code and import statement.

package com.xavor.groovyproject
import com.agile.agileDSL.ScriptObj.IBaseScriptObj
class GroovyClass {

void invokeScript(IBaseScriptObj obj) {

}

}

Once we do that we can go ahead and start implementing. Eclipse will help with the code completion.

Please note that since Groovy script is a dynamically type language and we can’t be certain of an object type at compile time, you might have to use variable declaration to make use of IntelliSense.

After the code is written, the last step is to copy it to the event handler in Java client.

RESOURCES

Share Now:

Let's make it happen

We love fixing complex problems with innovative solutions. Get in touch to let us know what you’re looking for and our solution architect will get back to you soon.