You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by dennis ch <de...@gmail.com> on 2010/07/02 09:46:32 UTC

JNI error under tomcat: java.lang.UnsatisfiedLinkError

Hi,

I have a java class (eval.java) that invokes a native method in an so file
(libmodel.so, using SWIG 1.3.29 to generate JNI code/wrapper and compiled
the library). I can use System.loadLibrary() to load the libmodel.so without
any error (-Djava.library.path=/usr/lib), and the native method initModel()
works fine as a standalone application.

However, when I deploy it as a web service (tomcat 6.0.26 + axis2 1.5.1 +
eclipse jee helios) to call the native method, I got the following error
(the first line means the .so was successfully loaded):

Load library successfully

[ERROR] com.model.modelJNI.initModel()V
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:194)
    at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:102)
    at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
    at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:173)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:167)
    at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:142)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.UnsatisfiedLinkError: com.model.modelJNI.initModel()V
    at com.model.modelJNI.initModel(Native Method)
    at com.model.model.initModel(model.java:13)
    at com.webservice.run(EvalVita.java:763)
    ... 25 more


Below is the body of Eval.java:

import com.model.*;

public class Eval {

  static void loadModel() {

    try {
        System.loadLibrary("model");

        System.out.println("Load library successfully");

    } catch (UnsatisfiedLinkError e) {

        System.err.println("Native code library failed to load." + e);

    }
  }
  public void run() {

    loadModel();
    model.initModel();
  }
}


Do I miss anything here?  Any input is appreciated!

Dennis

Re: JNI error under tomcat: java.lang.UnsatisfiedLinkError

Posted by dennis ch <de...@gmail.com>.
Ralph,

I got this error upon first deployment...

2010/7/4 Ralph Carlson <RA...@mediacomcc.com>

> do you get this error upon first deployment or re-deploy?
> do you restart tomcat after you redeploy your jni app?
> ________________________________________
> From: users-return-214329-RACARLSON=mediacomcc.com@tomcat.apache.org[users-return-214329-RACARLSON=
> mediacomcc.com@tomcat.apache.org] On Behalf Of Shay Rojansky [
> roji@roji.org]
> Sent: Saturday, July 03, 2010 12:40 AM
> To: Tomcat Users List
> Subject: Re: JNI error under tomcat: java.lang.UnsatisfiedLinkError
>
> Hi Dennis.
>
> So do you see the "Load library successful" message?
>
> Also, if I remember correctly, the code in eval.java is not a safe way to
> load a native library. It's a very good idea to place the
> System.loadLibrary
> in a static { } block, instead of in a method. The way your class is
> written, it's possible for the run method to be executed more than once, in
> which case loadLibrary will be called more than once (and so will the
> native
> initModels). Not sure what the effects are and if it's related to your
> problem but it's a good idea to avoid trouble by fixing it.
>
> Shay
>
> On Fri, Jul 2, 2010 at 3:46 AM, dennis ch <de...@gmail.com> wrote:
>
> > Hi,
> >
> > I have a java class (eval.java) that invokes a native method in an so
> file
> > (libmodel.so, using SWIG 1.3.29 to generate JNI code/wrapper and compiled
> > the library). I can use System.loadLibrary() to load the libmodel.so
> > without
> > any error (-Djava.library.path=/usr/lib), and the native method
> initModel()
> > works fine as a standalone application.
> >
> > However, when I deploy it as a web service (tomcat 6.0.26 + axis2 1.5.1 +
> > eclipse jee helios) to call the native method, I got the following error
> > (the first line means the .so was successfully loaded):
> >
> > Load library successfully
> >
> > [ERROR] com.model.modelJNI.initModel()V
> > java.lang.reflect.InvocationTargetException
> >    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >    at
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> >    at
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> >    at java.lang.reflect.Method.invoke(Method.java:597)
> >    at
> >
> org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:194)
> >    at
> >
> org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:102)
> >    at
> >
> org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
> >    at
> >
> org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
> >    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:173)
> >    at
> >
> org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:167)
> >    at
> > org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:142)
> >    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
> >    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> >    at
> >
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
> >    at
> >
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> >    at
> >
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
> >    at
> >
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
> >    at
> >
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
> >    at
> >
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
> >    at
> >
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
> >    at
> >
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
> >    at
> >
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
> >    at
> >
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
> >    at
> > org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
> >    at java.lang.Thread.run(Thread.java:619)
> > Caused by: java.lang.UnsatisfiedLinkError:
> com.model.modelJNI.initModel()V
> >    at com.model.modelJNI.initModel(Native Method)
> >    at com.model.model.initModel(model.java:13)
> >    at com.webservice.run(EvalVita.java:763)
> >    ... 25 more
> >
> >
> > Below is the body of Eval.java:
> >
> > import com.model.*;
> >
> > public class Eval {
> >
> >  static void loadModel() {
> >
> >    try {
> >        System.loadLibrary("model");
> >
> >        System.out.println("Load library successfully");
> >
> >    } catch (UnsatisfiedLinkError e) {
> >
> >        System.err.println("Native code library failed to load." + e);
> >
> >    }
> >  }
> >  public void run() {
> >
> >    loadModel();
> >    model.initModel();
> >  }
> > }
> >
> >
> > Do I miss anything here?  Any input is appreciated!
> >
> > Dennis
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: JNI error under tomcat: java.lang.UnsatisfiedLinkError

Posted by Ralph Carlson <RA...@mediacomcc.com>.
do you get this error upon first deployment or re-deploy? 
do you restart tomcat after you redeploy your jni app?
________________________________________
From: users-return-214329-RACARLSON=mediacomcc.com@tomcat.apache.org [users-return-214329-RACARLSON=mediacomcc.com@tomcat.apache.org] On Behalf Of Shay Rojansky [roji@roji.org]
Sent: Saturday, July 03, 2010 12:40 AM
To: Tomcat Users List
Subject: Re: JNI error under tomcat: java.lang.UnsatisfiedLinkError

Hi Dennis.

So do you see the "Load library successful" message?

Also, if I remember correctly, the code in eval.java is not a safe way to
load a native library. It's a very good idea to place the System.loadLibrary
in a static { } block, instead of in a method. The way your class is
written, it's possible for the run method to be executed more than once, in
which case loadLibrary will be called more than once (and so will the native
initModels). Not sure what the effects are and if it's related to your
problem but it's a good idea to avoid trouble by fixing it.

Shay

On Fri, Jul 2, 2010 at 3:46 AM, dennis ch <de...@gmail.com> wrote:

> Hi,
>
> I have a java class (eval.java) that invokes a native method in an so file
> (libmodel.so, using SWIG 1.3.29 to generate JNI code/wrapper and compiled
> the library). I can use System.loadLibrary() to load the libmodel.so
> without
> any error (-Djava.library.path=/usr/lib), and the native method initModel()
> works fine as a standalone application.
>
> However, when I deploy it as a web service (tomcat 6.0.26 + axis2 1.5.1 +
> eclipse jee helios) to call the native method, I got the following error
> (the first line means the .so was successfully loaded):
>
> Load library successfully
>
> [ERROR] com.model.modelJNI.initModel()V
> java.lang.reflect.InvocationTargetException
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>    at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>    at java.lang.reflect.Method.invoke(Method.java:597)
>    at
> org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:194)
>    at
> org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:102)
>    at
> org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
>    at
> org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
>    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:173)
>    at
> org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:167)
>    at
> org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:142)
>    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
>    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>    at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
>    at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>    at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
>    at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
>    at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
>    at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>    at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>    at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
>    at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
>    at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
>    at
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
>    at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.UnsatisfiedLinkError: com.model.modelJNI.initModel()V
>    at com.model.modelJNI.initModel(Native Method)
>    at com.model.model.initModel(model.java:13)
>    at com.webservice.run(EvalVita.java:763)
>    ... 25 more
>
>
> Below is the body of Eval.java:
>
> import com.model.*;
>
> public class Eval {
>
>  static void loadModel() {
>
>    try {
>        System.loadLibrary("model");
>
>        System.out.println("Load library successfully");
>
>    } catch (UnsatisfiedLinkError e) {
>
>        System.err.println("Native code library failed to load." + e);
>
>    }
>  }
>  public void run() {
>
>    loadModel();
>    model.initModel();
>  }
> }
>
>
> Do I miss anything here?  Any input is appreciated!
>
> Dennis
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: JNI error under tomcat: java.lang.UnsatisfiedLinkError

Posted by dennis ch <de...@gmail.com>.
Hi Shay,

Thanks for your input.  And yes, I did see the "Load library successful"
message.  I've also fixed the code with static { } block.  However, I still
received the same error message.  Any other thoughts?

Thanks,
Dennis

2010/7/2 Shay Rojansky <ro...@roji.org>

> Hi Dennis.
>
> So do you see the "Load library successful" message?
>
> Also, if I remember correctly, the code in eval.java is not a safe way to
> load a native library. It's a very good idea to place the
> System.loadLibrary
> in a static { } block, instead of in a method. The way your class is
> written, it's possible for the run method to be executed more than once, in
> which case loadLibrary will be called more than once (and so will the
> native
> initModels). Not sure what the effects are and if it's related to your
> problem but it's a good idea to avoid trouble by fixing it.
>
> Shay
>
> On Fri, Jul 2, 2010 at 3:46 AM, dennis ch <de...@gmail.com> wrote:
>
> > Hi,
> >
> > I have a java class (eval.java) that invokes a native method in an so
> file
> > (libmodel.so, using SWIG 1.3.29 to generate JNI code/wrapper and compiled
> > the library). I can use System.loadLibrary() to load the libmodel.so
> > without
> > any error (-Djava.library.path=/usr/lib), and the native method
> initModel()
> > works fine as a standalone application.
> >
> > However, when I deploy it as a web service (tomcat 6.0.26 + axis2 1.5.1 +
> > eclipse jee helios) to call the native method, I got the following error
> > (the first line means the .so was successfully loaded):
> >
> > Load library successfully
> >
> > [ERROR] com.model.modelJNI.initModel()V
> > java.lang.reflect.InvocationTargetException
> >    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >    at
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> >    at
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> >    at java.lang.reflect.Method.invoke(Method.java:597)
> >    at
> >
> org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:194)
> >    at
> >
> org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:102)
> >    at
> >
> org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
> >    at
> >
> org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
> >    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:173)
> >    at
> >
> org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:167)
> >    at
> > org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:142)
> >    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
> >    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> >    at
> >
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
> >    at
> >
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> >    at
> >
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
> >    at
> >
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
> >    at
> >
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
> >    at
> >
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
> >    at
> >
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
> >    at
> >
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
> >    at
> >
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
> >    at
> >
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
> >    at
> > org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
> >    at java.lang.Thread.run(Thread.java:619)
> > Caused by: java.lang.UnsatisfiedLinkError:
> com.model.modelJNI.initModel()V
> >    at com.model.modelJNI.initModel(Native Method)
> >    at com.model.model.initModel(model.java:13)
> >    at com.webservice.run(EvalVita.java:763)
> >    ... 25 more
> >
> >
> > Below is the body of Eval.java:
> >
> > import com.model.*;
> >
> > public class Eval {
> >
> >  static void loadModel() {
> >
> >    try {
> >        System.loadLibrary("model");
> >
> >        System.out.println("Load library successfully");
> >
> >    } catch (UnsatisfiedLinkError e) {
> >
> >        System.err.println("Native code library failed to load." + e);
> >
> >    }
> >  }
> >  public void run() {
> >
> >    loadModel();
> >    model.initModel();
> >  }
> > }
> >
> >
> > Do I miss anything here?  Any input is appreciated!
> >
> > Dennis
> >
>

Re: JNI error under tomcat: java.lang.UnsatisfiedLinkError

Posted by Shay Rojansky <ro...@roji.org>.
Hi Dennis.

So do you see the "Load library successful" message?

Also, if I remember correctly, the code in eval.java is not a safe way to
load a native library. It's a very good idea to place the System.loadLibrary
in a static { } block, instead of in a method. The way your class is
written, it's possible for the run method to be executed more than once, in
which case loadLibrary will be called more than once (and so will the native
initModels). Not sure what the effects are and if it's related to your
problem but it's a good idea to avoid trouble by fixing it.

Shay

On Fri, Jul 2, 2010 at 3:46 AM, dennis ch <de...@gmail.com> wrote:

> Hi,
>
> I have a java class (eval.java) that invokes a native method in an so file
> (libmodel.so, using SWIG 1.3.29 to generate JNI code/wrapper and compiled
> the library). I can use System.loadLibrary() to load the libmodel.so
> without
> any error (-Djava.library.path=/usr/lib), and the native method initModel()
> works fine as a standalone application.
>
> However, when I deploy it as a web service (tomcat 6.0.26 + axis2 1.5.1 +
> eclipse jee helios) to call the native method, I got the following error
> (the first line means the .so was successfully loaded):
>
> Load library successfully
>
> [ERROR] com.model.modelJNI.initModel()V
> java.lang.reflect.InvocationTargetException
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>    at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>    at java.lang.reflect.Method.invoke(Method.java:597)
>    at
> org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:194)
>    at
> org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:102)
>    at
> org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
>    at
> org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
>    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:173)
>    at
> org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:167)
>    at
> org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:142)
>    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
>    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>    at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
>    at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>    at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
>    at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
>    at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
>    at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>    at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>    at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
>    at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
>    at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
>    at
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
>    at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.UnsatisfiedLinkError: com.model.modelJNI.initModel()V
>    at com.model.modelJNI.initModel(Native Method)
>    at com.model.model.initModel(model.java:13)
>    at com.webservice.run(EvalVita.java:763)
>    ... 25 more
>
>
> Below is the body of Eval.java:
>
> import com.model.*;
>
> public class Eval {
>
>  static void loadModel() {
>
>    try {
>        System.loadLibrary("model");
>
>        System.out.println("Load library successfully");
>
>    } catch (UnsatisfiedLinkError e) {
>
>        System.err.println("Native code library failed to load." + e);
>
>    }
>  }
>  public void run() {
>
>    loadModel();
>    model.initModel();
>  }
> }
>
>
> Do I miss anything here?  Any input is appreciated!
>
> Dennis
>

Re: JNI error under tomcat: java.lang.UnsatisfiedLinkError

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dennis,

On 7/5/2010 3:35 AM, dennis ch wrote:
> modelJNI.java
> ===========
>  public final static native void initModel();
> 
> native code
> =========
> #include <HEC.h>
> #include <vector>
> #include <string>

[snip]

>  void initModel() {

You can't use JNI like that. You have to use the 'javah' header-fine
generator and then write your native code to that specification. For a
class called "JNITest" and a method called doSomething that takes no
arguments, the method signature needs to be:

JNIEXPORT void JNICALL Java_JNITest_doSomething
  (JNIEnv *, jclass);

You might want to read-up on using JNI: it's not as simple at the IJW
stuff C# provides.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwzZmQACgkQ9CaO5/Lv0PDqIQCfUHTmhYzd+iMN6z2ZS3F27z2p
WGgAni70v3qoAt66x+TuD0JUkRiFXeRZ
=Srci
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: JNI error under tomcat: java.lang.UnsatisfiedLinkError

Posted by dennis ch <de...@gmail.com>.
Hi Chris,

Thanks for your reply.  I recompiled everything and checked method
signature, but still got the same error.  I felt it's weird why it worked
for standalone app but not  deployed web service...  Thanks.

model.java
========
  public static void initModel() {
    modelJNI.initModel();
  }

modelJNI.java
===========
 public final static native void initModel();

native code
=========
#include <HEC.h>
#include <vector>
#include <string>

 string path="/tmp/model.xml";
 HEC *hec_obj;

 void initModel() {
   hec_obj = new HEC(path);

   if (!hec_obj) {
     cout << "[ERROR] Cannot instantiate HEC objects.";
   }
 }


2010/7/3 Christopher Schultz <ch...@christopherschultz.net>

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Dennis,
>
> On 7/2/2010 3:46 AM, dennis ch wrote:
> > However, when I deploy it as a web service (tomcat 6.0.26 + axis2 1.5.1 +
> > eclipse jee helios) to call the native method, I got the following error
> > (the first line means the .so was successfully loaded):
> >
> > Load library successfully
> >
> > [ERROR] com.model.modelJNI.initModel()V
> > java.lang.reflect.InvocationTargetException
>
> [...]
>
> > Caused by: java.lang.UnsatisfiedLinkError:
> com.model.modelJNI.initModel()V
> >     at com.model.modelJNI.initModel(Native Method)
> >     at com.model.model.initModel(model.java:13)
> >     at com.webservice.run(EvalVita.java:763)
> >     ... 25 more
>
> Sounds like a Java-class/native-library mismatch. Are you sure your
> .java file and .c files are sync'd up properly? Try recompiling
> everything, and double-check your JNI method signatures.
>
> What does modelJNI.initModel look like in the Java method declaration?
> What does the same method signature in your native code look like?
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkwv82YACgkQ9CaO5/Lv0PABewCeIC0qjqJdNm80GMByJBJn4VEs
> KzsAoKDPzdgXUJKMq/S4xruHd0RlNJCv
> =VA0U
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: JNI error under tomcat: java.lang.UnsatisfiedLinkError

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dennis,

On 7/2/2010 3:46 AM, dennis ch wrote:
> However, when I deploy it as a web service (tomcat 6.0.26 + axis2 1.5.1 +
> eclipse jee helios) to call the native method, I got the following error
> (the first line means the .so was successfully loaded):
> 
> Load library successfully
> 
> [ERROR] com.model.modelJNI.initModel()V
> java.lang.reflect.InvocationTargetException

[...]

> Caused by: java.lang.UnsatisfiedLinkError: com.model.modelJNI.initModel()V
>     at com.model.modelJNI.initModel(Native Method)
>     at com.model.model.initModel(model.java:13)
>     at com.webservice.run(EvalVita.java:763)
>     ... 25 more

Sounds like a Java-class/native-library mismatch. Are you sure your
.java file and .c files are sync'd up properly? Try recompiling
everything, and double-check your JNI method signatures.

What does modelJNI.initModel look like in the Java method declaration?
What does the same method signature in your native code look like?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwv82YACgkQ9CaO5/Lv0PABewCeIC0qjqJdNm80GMByJBJn4VEs
KzsAoKDPzdgXUJKMq/S4xruHd0RlNJCv
=VA0U
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: JNI error under tomcat: java.lang.UnsatisfiedLinkError

Posted by Ihor Chumak <ig...@gmail.com>.
Had You tried to made c header by javah -jni
./your_packages/your_class.class ?
It gives header for You with properly named method to be written in c..

On Mon, Jul 5, 2010 at 4:11 PM, Konstantin Kolinko
<kn...@gmail.com>wrote:

> 2010/7/2 dennis ch <de...@gmail.com>:
> > Do I miss anything here?  Any input is appreciated!
> >
>
> IIRC, native libraries can be loaded only once,
> but webapplication classloader is disposed and recreated each time the
> web application is stopped/reloaded. Thus the class that loads your
> library must be in ${catalina.base}/lib folder (and at the same time
> it must be removed from the webapp, because otherwise the classes in
> webapp are preferred over the ones in lib).
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
best regards,
    Igor Chumak

Re: JNI error under tomcat: java.lang.UnsatisfiedLinkError

Posted by Konstantin Kolinko <kn...@gmail.com>.
2010/7/2 dennis ch <de...@gmail.com>:
> Do I miss anything here?  Any input is appreciated!
>

IIRC, native libraries can be loaded only once,
but webapplication classloader is disposed and recreated each time the
web application is stopped/reloaded. Thus the class that loads your
library must be in ${catalina.base}/lib folder (and at the same time
it must be removed from the webapp, because otherwise the classes in
webapp are preferred over the ones in lib).

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org