Hi, Iam a beginner in JNI. I have an existing C++ library(Comp_Tree.a) from which i want to use some functions. Iam trying to use JNI in a servlet. ********My .java ************* import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; public class BasicServ extends HttpServlet { static { System.loadLibrary("Comp_Tree"); } /* Is this the library i have to load or give a new name to build a new library out of my Java code */ public void doGet(HttpServletRequest request, HttpServletResponse response) th
More>>
Hi,
Iam a beginner in JNI. I have an existing C++ library(Comp_Tree.a) from which i want to use some functions. Iam trying to use JNI in a servlet.
********My .java *************
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class BasicServ extends HttpServlet
{
static
{
System.loadLibrary("Comp_Tree"); }
/* Is this the library i have to load or give a new name to build a new library out of my Java code */
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "NMCView Report";
out.println("
cktid =
" + request.getParameter("cktid"));
out.println("
Calling C++ function
");
out.println("CKTID IS " + displayCompTre(request.getParameter("cktid")));
out.close();
}
public native String displayCompTre(String lnk_nm);
}
***** end of .java *************
I complied it, also created .h file using javah.
Now iam trying to create a wrapper C++ function which will call a function from my library. For this
########## .C file #######
#include
#include "BasicServ.h"
JNIEXPORT jstring JNICALL Java_BasicServ_displayCompTre
(JNIEnv *env, jobject jobj, jstring lnk_nm)
{
/* Here i want to call my function from the library. It's prototype is char* GetLnkId(char* lnk_nm) */
return lnk_nm;
}
######## end of .C file #########
Iam compling it using
aCC +z +u4 -c -D_HPUX -D_POSIX_C_SOURCE=199506L -I/opt/java/include -I/opt/java/include/hp-ux BasicServ.C
Shall I have to include the path of Comp_Tree library as well using -L option?
then iam making the library using
aCC -b -o libComp_Tree.sl BasicServ.o -lCsup -lstream -lstd
then iam trying to run my program from Internet Explorer using
http://servername:port/nmcview/servlet/BasicServ?cktid=07
Then getting the following error
Error: 500
Location: /nmcview/servlet/BasicServ
Internal Servlet Error:
java.lang.NoClassDefFoundError
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Class.java:241)
at org.apache.tomcat.core.ServletWrapper.initServlet(ServletWrapper.java:298)
at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:445)
at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:597)
at org.apache.tomcat.servlets.InvokerServlet.service(InvokerServlet.java:257)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:160)
at org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338)
at java.lang.Thread.run(Thread.java:479)
Please help me in resolving this error..
Thanks,
Radha
<<Less