Skip to Content

Groovy scripts in your HCI integration flows have the combined class libraries of Groovy and Java available to them. Sometimes, though, you also need to access classes from external Java libraries. Luckily, you can do that. However, this useful feature is only mentioned in passing in the HCI Developer’s Guide, and particularly if you are new to Eclipse, it is not obvious how it works. In this blog I will walk you through the required steps.

Before we get started, let me point out that adding external libraries is currently only possible in the Eclipse add-on. I expect the feature to be added to the Web UI sooner or later, though.

Step 1: Create the src.main.resources.lib package

The JAR files containing your external Java libraries must be imported into the src.main.resources.lib package of your integration project. Since this package is not created automatically in a new project, we need to add it manually. To do so, right-click your project, click New and choose Package. In the New Java Package window, enter src.main.resources.lib in the Name field and click Finish.

A freshly created integration project with the package added looks like this:

Step 2: Import your JAR file

Having created the package, the next step is to import the JAR file containing the external Java library. Right-click the src.main.resources.lib package and choose Import… from the context menu. In the Import window, choose File System in the General category and click Next. Now click Browse and navigate to the directory containing your JAR file and click OK. From the list of files in the chosen directory, check the JAR file to be imported and click Finish:

The library has now been imported into the proper package. If you need more than one library, you can go ahead and import multiple JAR files.

One restriction to keep in mind: The Java Virtual Machine executing your Groovy code runs Java version 1.7, so for now you cannot use Java 1.8 libraries. As always with cloud software, this can and probably will change in the future.

Step 3: Utilise the external classes in your code

The classes of the external library are now available in your Groovy code. At this point, you would usually import them at the top of the script, and then reference them by class name in the code. And that is all there is to it 🙂

Bonus: How to determine the Java version

How did I determine that HCI’s underlying JVM is version 1.7? The getProperty method of class java.lang.System lets you look at various system properties, including the Java version. At the time of writing, System.getProperty("java.version") returned 1.7.0_121. For a full list of supported properties, check out the method’s documentation.

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. Sayyad Rahman

    Hi,

    I wonder how to upload these libraries so that these scripts can consume them during runtime. Deploying the artifact on tenant does not seems to be uploading these libraries.

     

    Thanks..!

    (0) 
    1. Morten Wittrock Post author

      Hi Sayyad

      At the moment you need to do it in Eclipse. Some resource editing has been added to the Web UI just recently, however, and I’m sure uploading JAR files will be added as well.

      Regards,

      Morten

      (0) 
  2. Sayyad Rahman

    Hey,

    Thanks for the reply. I did package and upload it via eclipse but somehow groovy scripts are unable to refer them. have raised ticket with SAP.

    (0) 

Leave a Reply