Calling Java/Python/Javascript class from an xlate

When running code outside of the engine, the programmer is responsible for memory and file management, process blocking, error handling, and so on.

The Java compiler JDK (javac) is not provided by the system.

Classes should be compiled with the same version, or earlier version, used by the system.

The classes can be compiled on another computer and then transferred to the system server. You can also install Java JDK on the system server and compile the class with the javac command.

After a Java class is compiled, place the class into the site java_uccs directory.

Run java classes with exec from Tcl procs and xlate Tcl fragments using the command exec java class name. Do not include the .class file extension with the class name. The Tcl code captures and uses what is returned by the Java class.

Some java classes must reference Java code included in java jar files such as Java database drivers:

  • The .jar files can be transferred to the system server.
  • The CLASSPATH environmental variable must be updated to include the path to this new jar file.

You can test the Java class and a referenced java .jar file from the command line. To do this, update CLASSPATH with this command, or similar, depending on the shell:

export CLASSPATH=$CLASSPATH:<path to the .jar file>

To run a Java class and a referenced java .jar file from Tcl or an xlate Tcl fragment, use this code as an example:

global env
set jar [file join $::HciSiteDir java_uccs classes12.jar]
set class helloworld
set env(CLASSPATH) "$env(CLASSPATH)$jar"
set xlateOutVals [list [exec java $class]]        

This code demonstrates how to access and modify the CLASSPATH environment variable. It also shows how to exec the Java class and how to capture the return data from the Java class.

Modify the code to point to your class and .jar. This code works both in an xlate Tcl fragment and in an xlate XLTP Tcl procedure.