To Load the terrJava Package
Prepare your system before you load the terrJava package. After
your system is prepared, you can load the package by calling
library()
.
Before loading the terrJava package, you must set the
JAVA_HOME
environment variable to the base of the Java
installation. This can be read within
TERR
with:
Sys.getenv("JAVA_HOME")
If this is the empty string, set it to the directory where Java is installed with a call such as:
Sys.setenv(JAVA_HOME="/usr/lib/jvm/java-7-sun/")
Alternatively, you can set the
JAVA_HOME
environment variable before starting
TERR.
The terrJava package is included with the TERR built-in libraries. You can load it with:
library(terrJava)
If the library loads without errors, you can test calling into Java by executing the following expressions, both of which should return the number 8:
.JavaMethod("java/lang/Math", "pow", "(DD)D", 2, 3)
.JavaMethod("com/tibco/terr/TerrJava", "testPow", "(DD)D", 2, 3)
Example
The following example demonstrates setting the
JAVA_HOME
environment variable, starting
TERR,
loading the terrJava package, and running the tests on Linux:
testlabl6406 ~% setenv JAVA_HOME /usr/lib/jvm/java-7-sun/
testlabl6406 ~% TERR
Cannot read termcap database; using dumb terminal settings.
TIBCO Software Inc. Confidential Information
Copyright (C) 2011-2016 TIBCO Software Inc. ALL RIGHTS RESERVED
TIBCO Enterprise Runtime for R version 4.2.0 for Linux 64-bit
Type 'help()' for help.
Type 'q()' to quit.
> library(terrJava)
> .JavaMethod("java/lang/Math", "pow", "(DD)D", 2, 3)
[1] 8
> .JavaMethod("com/tibco/terr/TerrJava", "testPow", "(DD)D", 2, 3)
[1] 8