----------------------------- Please read the FAQ! <http://java.apache.org/faq/> ----------------------------- Hi, We are facing the problem of running JNI from a Servlet where JNI has return type other than void. WE ARE ALWAYS GETTING java.lang.UnsatisfiedLinkError. If we are using only JNI (NOT JNI FROM SERVLET) we are getting the desired result for all sorts data return type from JNI. But Not With Servlet-JNI. We are in real soup!!!! We are using Apache Jserv 1.05b Apache 1.3.6 Linux 5.2 (REDHAT Distribution) Kernel 2.0.36. We have kept all our .so* files under /usr/lib The Code we are using: -------------------------------------------- CODE of HelloSrvStr.java: ---------------------------------------------- import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloSrvStr extends HttpServlet { public native String displayHelloSrvStr(); static { System.loadLibrary("HelloSrvStr"); } protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<HTML><HEAD><TITLE>Hello Client!</TITLE>"+"</HEAD><BODY>") ; out.println("Servlet calls jni"); String hello = new HelloSrvStr().displayHelloSrvStr(); out.println("<br>"+hello+"<br>"); out.println("<br>"+"hello"+"<br>"); out.println("</BODY></HTML>"); out.close(); } } ------------------------------------------------------- HelloSrvStr.h generated via javah -jni HelloSrvStr /* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class HelloSrvStr */ #ifndef _Included_HelloSrvStr #define _Included_HelloSrvStr #ifdef __cplusplus extern "C" { #endif /* * Class: HelloSrvStr * Method: displayHelloSrvStr * Signature: ()Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_HelloSrvStr_displayHelloSrvStr (JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif ------------------------------------------------------- The C Code for HelloSrvStr.c #include <jni.h> #include "HelloSrvStr.h" #include <stdio.h> #include <string.h> JNIEXPORT jstring JNICALL Java_HelloSrvStr_displayHelloSrvStr (JNIEnv *env, jobject obj) { char inbuf[12]; memset(inbuf,'\0',12); strcpy(inbuf , "Hello Hi"); printf("%c \n",inbuf); printf("Hello World\n"); return (*env)->NewStringUTF(env,inbuf); } ------------------------------------------------------- When we are running the Servlet from Browser we are getting an Internal Server Error. On inspection of mod_jserv we found [29/07/1999 11:06:20:687] (ERROR) ajp11: Servlet Error: java.lang.UnsatisfiedLin kError: displayHelloSrvStr: displayHelloSrvStr ______________________________________________________ TO mention here if the return type of JNI is Void, the servlet is running without any error. Regards, Dipankar Chakrabarti Senior Manager - Projects Hinditron Informatics Limited, India === DIPANKAR CHAKRABARTI Have a Nice Time............ _____________________________________________________________ Do You Yahoo!? Free instant messaging and more at http://messenger.yahoo.com -- -------------------------------------------------------------- Please read the FAQ! <http://java.apache.org/faq/> To subscribe: [EMAIL PROTECTED] To unsubscribe: [EMAIL PROTECTED] Archives and Other: <http://java.apache.org/main/mail.html/> Problems?: [EMAIL PROTECTED]
