class file for javax.serverlet.GenericServlet not found

2.7k Views Asked by At

I have stuck in the class->header file for couple days!

I have tried on jni on Client by http://netbeans.org/kb/docs/cnd/beginning-jni-linux.html and http://ringlord.com/jni-howto.html. And it succeeded in return "hello JNI C++" from JNI's (.cpp)file. Here are my steps:

  1. create native function and in client.java
  2. clean &build this client.java on Netbeans IDE, then result a client.class file
  3. javah –jni [package].[classname]
  4. create a dynamic library C++ project as first reference does, and put client.h into source file, and put some hello code into (.cpp)file ---> It works!

However, I tried to do the same thing on the servlet side and it's not working

  1. Servlet.java->Servlet.class : ok!
  2. Servlet.class->Servlet.h: fail!!!! Error : cannot access javax.servlet.GenericServlet class file for javax.servlet.GenericServlet not found

The following are solutions I have found and tried so far,

  • check the package name

  • sudo gedit /etc/profile,sudo gedit .bashrc, sudo /etc/environment; add JAVA_HOME & CLASSPATH on them, and source them to update, then echo $JAVA_HOME, echo $CLASSPATH to verify

  • download servlet-api-6.0.14.jar & servlet-api-5.0.16.jar from http://www.jarfinder.com/index.php/java/info/javax.servlet.GenericServlet ,and add above two (.jar) by netbeans IDE->server->property->libraries->Add JAR

Please tell me how to figure it out this issue, thank you very much!!Btw, I am using hessianServlet

1

There are 1 best solutions below

4
On BEST ANSWER

NativeWrapper.java (you run javah only on this class)

class NativeWrapper {
  // either
  static {
    System.loadLibrary("MyOpenCVNative");
  }
  // or
  public NativeWrapper() {
    System.loadLibrary("MyOpenCVNative");
  }
  public native void callNative();
}

MyServlet.java

class MyServlet extends javax.servlet.GenericServlet {
  private NativeWrapper nativeWrapper = new NativeWrapper();

  public void someServletMethod() {
    nativeWrapper.callNative();
  }
}