Hi,

linux 2.0.38
java 1.1.7B


I am trying to get a handle to a remote
object from C.  In my C program, I create
a VM, find the class I want, find the method
and then call CallStaticIntMethod().  It
appears that Naming.lookup() is the cause
of my NoClassDefFoundError, since if I
comment this line out in the java code
things seem to work.

Digging around on the JDC the only similar
problem I found involved applets in browsers.
In this case the conclusion was that the
browser didn't support rmi.

Does anyone know of any limitations on VMs
created via JNI_CreateJavaVM()?

I will append some code below, in case I am
doing something obviously wrong.

thanks,

jp


[jape@jaguar test2]$ pwd
/home/jape/test2
[jape@jaguar test2]$ echo $CLASSPATH
/home/jape
[jape@jaguar test2]$ echo $LD_LIBRARY_PATH
/usr/local/java/lib/i386/native_threads/
[jape@jaguar test2]$ cat Makefile
ALL:
        javac *.java
        rmic test2.Server

clean:
        rm *.class

spawn: spawn_jvm.c
        cc -Wall -I/usr/local/java/include
-I/usr/local/java/include/genunix  -o
 spawn  spawn_jvm.c  -L/usr/local/java/lib/i386/native_threads/  -ljava
[jape@jaguar test2]$ ./spawn
classpath=
/usr/local/java/lib/i386/native_threads//../../../classes:/usr/local/
java/lib/i386/native_threads//../../classes.zip:/usr/local/java/lib/i386/native_
threads//../../classes.jar:/usr/local/java/lib/i386/native_threads//../../rt.jar
:/usr/local/java/lib/i386/native_threads//../../i18n.jar:/usr/home/jape
before calling static method
result is =0
exception detected : after call static obj method
java.lang.NoClassDefFoundError                                 



code:


package test2;

import java.rmi.*;


public class Native  {
   private static ServerInterface factory = null;


   private static ServerInterface getFactory() {
      if ( factory == null ) {
         if ( System.getSecurityManager() == null ) 
             System.setSecurityManager(new RMISecurityManager());

         try { 
            factory = (ServerInterface)
              java.rmi.Naming.lookup( "rmi://localhost/Server" );
   
         } catch (Exception e ) {
             e.printStackTrace();
         }

      }
      return factory;
   }

   public static int create ( ) {
   
      try { 
         ServerInterface result =  getFactory();

         return 10 ;

      } catch (Exception e ) {
          e.printStackTrace();
          return 6;
      }
   }


}


#include <jni.h>

#ifdef _WIN32
#define PATH_SEPARATOR ';'
#else /* UNIX */
#define PATH_SEPARATOR ':'
#endif

#define USER_CLASSPATH "/usr/home/jape"


void checkException( JNIEnv *env, char * string ) {
    jthrowable exp;
    
    exp = (*env)->ExceptionOccurred(env);
    if (exp) {
        fprintf( stderr, "exception detected : %s\n", string);
        (*env)->ExceptionDescribe(env);
        (*env)->ExceptionClear(env);
    }


}

int  main() {
    JNIEnv *env;
    JavaVM *jvm;
    JDK1_1InitArgs vm_args;
    jint res;
    jclass cls;

    jmethodID mid;
    jobjectArray args;
    char classpath[1024];
    jobject visual;
    jthrowable exp;
    int result;

    /* IMPORTANT: specify vm_args version # if you use JDK1.1.2 and
beyond */
    vm_args.version = 0x00010001;

    JNI_GetDefaultJavaVMInitArgs(&vm_args);

    /* Append USER_CLASSPATH to the end of default system class path */
    sprintf(classpath, "%s%c%s",
            vm_args.classpath, PATH_SEPARATOR, USER_CLASSPATH);
    vm_args.classpath = classpath;

   fprintf(stderr, "classpath= %s\n", vm_args.classpath);

    /* Create the Java VM */
    res = JNI_CreateJavaVM(&jvm,&env,&vm_args);
    if (res < 0) {
        fprintf(stderr, "Can't create Java VM\n");
        exit(1);
    }
   checkException ( env, "after create vm" ); 

    cls = (*env)->FindClass(env, "test2/Native");
    if (cls == 0) {
        fprintf(stderr, "Can't find Native class\n");
        exit(1);
    }
   checkException ( env, "after find class " ); 
 
    mid = (*env)->GetStaticMethodID(env, cls, "create", "()I");
    if (mid == 0) {
        fprintf(stderr, "Can't find ggi create\n");
        exit(1);
    }
    checkException ( env, "after get static method"); 

    args = 0;

    fprintf(stderr, "before calling static method\n" );
    result = (*env)->CallStaticIntMethod(env, cls, mid, args);

    fprintf(stderr, "result is =%d\n", result);
    checkException( env, "after call static obj method");

    (*jvm)->DestroyJavaVM(jvm);

    return 0;

}


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to