Java Native Interface (JNI) - how to handle the object returned from C to java

I am new to JNI,

this is a way i am tryig out.

I defined java class as

public class sample2struc

{

public String Myname;

public void sample1struc() {};

public void setMyname(String Myname)

{

this.Myname = Myname;

}

public String getMyname()

{

return Myname;

}

}

the c implementation

JNIEXPORT jobject JNICALL Java_sample1_readFile

(JNIEnv *env, jobject obj)

{

struct emp e;

strcpy(e.name,"Siva");

jclass cls = env->FindClass("sample1struc");

jmethodID mid = env->GetMethodID(cls,"<init>","()V");

jobject xinstance = env->NewObject(cls,mid);

jmethodID setterid = env->GetMethodID(cls,"setSCPname","(Ljava/lang/String;)V");

xinstance = env->NewObject(cls,setterid,&e.no);

return cls;

}

my main problem started here, i dont know how to catch the cls object and retrieve the data from that class.

In fact i need to pass the structure array from C to java and retriev those details in java and display them on JSP screen.

Can any one please help me out in this issue.

[1186 byte] By [kots@indiaa] at [2007-11-26 23:21:46]
# 1

If you want a C method to be invokable by Java, or vice-versa, it would behoove you to provide middle-man "proxy" methods to take language-neutral parameters, such as taking or returning XML, which could then serialize/deserialize the XML into/from the native types and invoke the actual method.

warnerjaa at 2007-7-10 14:26:19 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
thanks for your response,is there any way of doing this using JNI. it is a commercial application, i need to get approval from the clent for using new technology like XML. Currently i can use only C++ and Java, can u please suggest me in handling this scenario using JNI
kots@indiaa at 2007-7-10 14:26:19 > top of Java-index,Java HotSpot Virtual Machine,Specifications...