.JavaMethod(X, METHOD, SIGNATURE, ..., client = F) .JavaField(X, FIELD, SIGNATURE, client = F) .JavaAttachClassPath(paths, function(paths, client = F) is.jvm.running() require.java()
.JavaMethod
this must be the
full method descriptor, or signature.
When calling
.JavaField
it is the class
descriptor (signature) of the return value.
The
javap
utility included with the Java 2 SDK
can be used to print out the JNI field and method decriptors for a class.
% javap -s -p java.lang.Math Compiled from Math.java public final class java.lang.Math extends java.lang.Object { public static final double E; /* D */ public static final double PI; /* D */ ... public static double abs(double); /* (D)D */ public static float abs(float); /* (F)F */ public static int abs(int); /* (I)I */ public static long abs(long); /* (J)J */ ... public static double toDegrees(double); /* (D)D */ public static double toRadians(double); /* (D)D */ }
.JavaAttachClassPath
adds these to the Java classpath list
which is searched to find classes by
.JavaMethod
and
.JavaField
.
...
argument for each class descriptor enclosed in
the parentheses of the
SIGNATURE
argument.
All S-PLUS atomic types, except
complex
, can be passed to a Java method.
The S-PLUS objects will be converted to Java types according to the
class descriptors in the
SIGNATURE
argument.
.JavaMethod
and
.JavaField
returns an S object containing the value returned by the Java method or
the Java class field value.
If the result is a Java primitive, array of primitives, String, or array of Strings, then it will be converted to a vector of the corresponding S-PLUS type.
If the result is an array of non-primitive objects or a class implementing the java.util.Collection interface, then it will be converted to a S-PLUS list with each component of the array or Collection returned as one component of the list. Classes implementing Collection include Vector and ArrayList.
For any other class the result will be converted to a single String using
the object's
toString()
method.
The function
is.jvm.running
returns true
if Java is currently running, otherwise false.
The other functions return NULL.
The functions
.JavaMethod
and
.JavaField
and
.JavaAttachClassPath
will automatically start Java by calling
require.java
,
if it is not already running.
In order for the Java Virtual Machine to find Java classes, either
(1) the class file directories and jar files must be included in
the Java classpath by setting the CLASSPATH environment variable,
or (2) the classes must be placed in a jar file in the
directory SHOME/java/jre/lib/ext,
or (3) the class file directories and jar files must be
attached by a call to
.JavaAttachClassPath
.
In cases (1) and (3), if the Java classes are in a "jar" file, the location should be the full path to the jar file including the name of the file. If the class files are in a directory, the location should be the full path to the directory.
.JavaMethod("java/lang/Math", "pow", "(DD)D", 2, 10) .JavaField("java/lang/Math", "PI", "D") .JavaMethod("java.lang.System", "getProperty", "(Ljava/lang/String;)Ljava/lang/String;", "java.version") .JavaMethod("java.lang.Double", "isNaN", "(D)Z", NaN) is.inf(.JavaField("java.lang.Double", "POSITIVE_INFINITY", "D")) .JavaField("java.lang.Integer", "MAX_VALUE", "I")