Using the Java Definition Type

Note: To run Java processes on a Platform Agent, Java needs to be installed on the Platform Agent computer.

Note: You must assign at least one Process Server to run Java definitions in order to use the Java Definition Type.

Interpreter

By default, Java is found via the PATH environment variable. You can override this by setting the LocalInterpreter_JAVA Process Server parameter to the desired path (for example, /usr/lib/jvm/java-11/bin/java). You can also specify a list of allowed interpreters at the Process Server level using the InterpreterWhitelist_JAVA Process Server parameter. This parameter takes a regular expression that must match the value of the JCS_INTERPRETER_JAVA parameter.

You can override the default interpreter at the Process Definition level with the JCS_INTERPRETER_JAVA Process Server parameter. Simply create the parameter and point it to an interpreter that has been whitelisted using the InterpreterWhitelist_JAVA Process Server parameter.

Environment

For more information about predefined variables and how to create per-system or per-user environment variables, see Using Platform Definition Types.

Variables and Parameters

To access and manipulate Process Definition parameters in the Java Source script, simply use their names, as you do in use RedwoodScript syntax. For example, if you have a Process Definition parameter named defultDuplicateDefinitionName, you can access it in a Java Source script like so:

jcsErr.println(defaultDuplicateDefinitionName);
String[] objectNames = defaultDuplicateDefinitionName.split(":");

Returning an Error

You can set the return code for a Java script the same way you do for RedwoodScript. For example:

jcsJobContext.setReturnCode(400);

Examples

This example shows how to use parameters, exposed as environment variables.

Copy
System.out.println(String.format("Number of processors: %s.", System.getenv("NUMBER_OF_PROCESSORS")));

This example shows how to pass numeric (numberParam) and string (stringParam) parameters to and from Java code.

Copy
{
  stringParam = stringParam + ".exe";
  numberParam = BigDecimal.valueOf(1000.0);
  System.out.println(numberParam);
  System.out.println(stringParam);
}