Using the Java Object
About the Java Object
The Java object provides a mechanism that is similar to the Java Native Interface (JNI)
for instantiating Java classes and accessing fields and methods on the resultant objects.
You can create hybrid applications that contain both Java and DATA step code.
CLASSPATH and Java Options
In previous versions of SAS, Java classes were found using the JREOPTIONS system
option.
In SAS, you must set the CLASSPATH environment variable so that the Java object can
find your Java classes. The Java object represents an instance of a Java class that is
544 Chapter 24 Using DATA Step Component Objects
found in the current Java classpath. Any class that you use must appear in the classpath.
If the class is in a .jar file, then the .jar filename must appear in the classpath.
How you set the CLASSPATH environment variable depends on your operating
environment. For most operating systems, you can set the CLASSPATH environment
variable either locally (for use only in your SAS session) or globally. Table 24.1 on page
545 shows methods and examples for different operating environments. For more
information, see the SAS documentation for your operating environment.
Table 24.1 Setting the CLASSPATH Environment Variable in Different Operating
Environments
Operating
Environment Method Example
Windows
Globally Windows System
Environment Variable
in Control Panel
Control Panel ð System ð Advanced ð
Environment Variables (Windows XP Classic
view)
SAS configuration file
set classpath c:\HelloWorld.jar
Locally SAS command line
-set classpath c:\HelloWorld.jar
UNIX
Globally SAS configuration file
set classpath ~/HelloWorld.jar
Locally
EXPORT command
*
export classpath=~/HelloWorld.jar;
z/OS
Globally TKMSENV data set
set TKJNI_OPT_CLASSPATH=/u/userid/java:
/u/userid/java/test.jar: asis
Locally Not available
VMS
Globally
Command line
**
$ define java$classpath disk:[subdir]
abc.jar, disk:[subdir2]def.jar
detach_template.com
script that is generated
in sas$root:
[misc.base] at
installation
define java$classpath disk:[subdir]
abc.jar, disk:[subdir2]def.jar
Locally Not available
*
The syntax depends on the shell.
**
The command line should be defined before you invoke SAS so that the process that the JVM actually
runs in gets the definition as well.
Using the Java Object 545

Get SAS 9.4 Language Reference, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.