Skip to Content

RunJava

RunJava allows you to:

  • Run inline Java code that will be compiled before the execution. You can think about it as a script in Java.

  • Execute Java methods from prelimanary complied Java libraries.

RunJava works as follows. The Java code from the main editor is wrapped as a static method in a class. The class code is pre-appended by the lines from the Imports field. The class is then compiled and the static method is executed. The static method has one parameter il, which is a Java object implementing the following interface:

// It returns the value of a variable looking up first in the context variable and then, if not found, in the application variables. // It returns null is the varible does not exist. public String getVariableValue (String name); // It updates (if such variable exists) or sets (if such variable does not exist) context variable. public void setContextVariable (String name, String value);

To use Java libraries you need to copy them to the server where InfoLink is installed into the INFOLINK_HOME/libs directory. All files and subfolder in the directory will be added to the class path and loaded on execution. If you need to replace a library with its new version, you have to restart InfoLink for the replacement to take effect.

Use Execute button to compile and run your code during development. The output (everything you print to System.out) will be displayed in the output console under the main editor. The output console will contain compilation errors if any.

Example 1: Execute inline Java code that gets the value of an app variable hisName, calles a Java library, and set a context variable hisName (you can find the example in our Tutorial app: RunJava scenario)

Import:

import strman.Strman;

Main editor:

System.out.print("Hi "); System.out.print(il.getVariableValue("hisName")); System.out.println(" !"); il.setContextVariable("myName", "Groot"); String messageNormalized = Strman.collapseWhitespace("I am Groot"); System.out.println(messageNormalized);

To make this example work we preliminarily copied strman-0.4.0.jar to INFOLINK_HOME/libs. You can find the library at https://github.com/shekhargulati/strman-java 

Last updated on