Hi,
I am using a servlet call to a C dll with JNI. I am using Windows NT4,
TOMCAT 3.2, jdk1.3, c dll. Below is my code....
#################################################
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class jniServlet2 extends HttpServlet {
public String myString = null;
public native String displayHelloWorld();
public void init() throws ServletException
{
try {
//System.load("d:\\work\\jni\\hello.dll");
System.loadLibrary("hello");
} catch(Exception e) {
System.err.println("error1-> " + e);
return;
} catch(Throwable e) {
System.err.println("error2->" + e);
return;
}
System.err.println("Successfully loaded DLL");
myString = new jniServlet2().displayHelloWorld();
}
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println( myString );
out.println("</body>");
out.println("</html>");
}
}
#############################################
In the Tomcat console "Successfully loaded DLL" is printed. However, the
native method displayHelloWorld() terminates the code abnormally.
The error I'm receiving in the browser is an UnsatisfiedLinkError as
follows...
#################################################
Internal Servlet Error:
java.lang.UnsatisfiedLinkError: displayHelloWorld
at jniServlet2.displayHelloWorld(Native Method)
at jniServlet2.init(jniServlet2.java:34)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at
org.apache.tomcat.core.ServletWrapper.doInit(ServletWrapper.java:317)
at org.apache.tomcat.core.Handler.init(Handler.java:215)
at
org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java:296)
at org.apache.tomcat.core.Handler.service(Handler.java:254)
at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:210)
at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
########################################################################
The code for the c dll Implemation is as follows....
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
#include <string.h>
JNIEXPORT jstring JNICALL Java_HelloWorld_displayHelloWorld
(JNIEnv *env, jobject obj)
{
jstring value;
char buf[40];
strcpy(buf,"HelloWorld");
value = (*env)->NewStringUTF(env,buf);
return value;
}
#########################################################
I've tried adding the dll path to the SYSTEM and USER path, and I've tried
the load() and loadLibrary() appraoches, but Tomcat is just not finding the
dll......
Can anyone please help......
Adrian.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]