Operating System - HP-UX
1829467 Members
1480 Online
109991 Solutions
New Discussion

Problem launching JVM from within a shared library

 
Simon Brown_3
Occasional Contributor

Problem launching JVM from within a shared library

We are writing a plugin for a commercial product to customise it for our use. The plugins are in the form of .sl files. What we're trying to do is, via JNI, load a JVM and launch some Java code from within this plugin. However, the output from the plugin gives the following error:

"There was an error trying to initialize the HPI library.
Please check your installation, HotSpot does not work correctly
with any JDK 1.1.x release."

The same JNI code works fine within a standalone executable. The SHLIB_PATH settings are the same for both the standalone executable and the application we're plugging in to.

The code is as follows:

#include
#include
#include
#include

int ExitRcProtoConn_C( In_TlsSessionInfo_t *tls_info, In_ExitRcProtoConn_t *in, Out_ExitRcProtoConn_t *out )
{
memset(out, 0, sizeof(*out));

if (in->protocol != ITP_PROTO_HTTP)
{
return 0;
}

char* buffer;

JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
jint res;
jclass cls;
jmethodID mid;
jstring user;
jstring password;
jstring hostname;
jobjectArray args;
char classpath[1024];

JavaVMOption options[4];

options[0].optionString = (char*) "-Djava.class.path=/home/tstxfb:/home/tstxfb/log4j.jar:/home/tstxfb/wcxfb.jar:.:/opt/java1.4/jre/lib/rt.jar"; /* user classes */
options[1].optionString = (char*) "-Djava.compiler=NONE";
options[2].optionString = (char*) "-verbose:jni,class,gc";


vm_args.version = JNI_VERSION_1_4;
vm_args.options = options;
vm_args.nOptions = 3;
vm_args.ignoreUnrecognized = 1;

/* Create the Java VM */
printf("Creating VM\n");
res = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);
if (res < 0) {
fprintf(stderr, "Can't create Java VM: %d\n", res);

return(-1);
}

printf( "Locating class\n");
cls = env->FindClass( "com/amadeus/webcom/xfb/LdapAuthenticator");
if (cls == 0) {
fprintf(stderr, "Can't find LdapAuthenticator class\n");
return(-1);
}

printf( "Finding Method\n");
mid = env->GetStaticMethodID( cls, "authenticateObfuscated",
"(Ljava/lang/String;Ljava/lang/String;)Z");
if (mid == 0) {
fprintf(stderr, "Can't find authenticateObfuscated() method\n");
return(-1);
}


printf( "Creating strings\n");
user = env->NewStringUTF( in->login_user);
if (user == 0) {
fprintf(stderr, "Out of memory\n");
return(-1);
}

password = env->NewStringUTF( in->login_password);
if (password == 0) {
fprintf(stderr, "Out of memory\n");
return(-1);
}

hostname = env->NewStringUTF( in->http_host_name);
if (hostname == 0) {
fprintf(stderr, "Out of memory\n");
return(-1);
}

printf( "Calling Java code\n");
bool result = env->CallStaticBooleanMethod( cls, mid, user, password,
hostname);

jvm->DestroyJavaVM();

if (result)
{
return 1;
}
return -1;

}

Can anyone shed any light on this?
1 REPLY 1
Mike Stroyan
Honored Contributor

Re: Problem launching JVM from within a shared library

You might get useful information by running the plugin with the tusc system call reporting utility. That may, for example, show that the jvm was looking for libhpi and not finding it because it wasn't in the shared library search path.
You can download tusc from
http://h21007.www2.hp.com/dspp/tech/tech_TechSoftwareDetailPage_IDX/1,1703,1433,00.html