Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

java.lang.UnsatisfiedLinkError

Hi there i am having this problem.

I am deploying my application into FreeBSD machine and it's showing me this error.

Acutually i am deploying the .so file and it's giving this error. As far i understand it;s a library file in Unix machine. and i have store that file in the /WEB-INF or even set the file in the FreeBSD CLASSPATH.

Any ideas how can i sovle this?
0
wjh7554
Asked:
wjh7554
  • 13
  • 11
  • 7
  • +1
1 Solution
 
CEHJCommented:
It needs to be on $LD_LIBRARY_PATH
0
 
objectsCommented:
put it somewher ein LD_LIBRARY_PATH, or add the directory it is in to that path
0
 
wjh7554Author Commented:
i have tried...

private static final String MC_LIB_NAME = "readArray";  //mc tool library used for forming matrices

            String strLibPath="/Netra/Tomcat/webapps/netra/WEB-INF/lib/";
            System.setProperty("LD_LIBRARY_PATH", strLibPath);
            System.setProperty("java.library.path", strLibPath);      
            System.loadLibrary(MC_LIB_NAME); //loading mc library

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
wjh7554Author Commented:
still giving me that error
0
 
objectsCommented:
setProperty() does not set OS environment properties, it only sets java syste,m properties.
You need to set LD_LIBRARY_PATH in the OS before running your app
0
 
wjh7554Author Commented:
object, can share me the ideas on how to set the LD_LIBRARY_PATH to the OS level?

is it the same where i did for my CLASSPATH and JAVA_HOME? I set it (in FreeBSD) in the .cshrc file.
0
 
objectsCommented:
> is it the same where i did for my CLASSPATH and JAVA_HOME? I set it (in FreeBSD) in the .cshrc file.

yes, exactly the same.
0
 
wjh7554Author Commented:
object, i just notice a error.

I am trying to deploy the system into FreeBSD, running the Tomcat AppServer.

I packed the application in .war with Eclipse and i notice that the .war i packed, didnt consits of .SO file but i certainly confirm physically it's there. Is that means, i can't pack the .so file in eclipse or i cant pack the .so in .war file?
0
 
objectsCommented:
a war is just a zip so theres no reason you cannot include it.
Does eclipse give you the option to check what files to include and what not to (I always use build scripts to handle deployment).
0
 
CEHJCommented:
Why, btw, are you *deploying* a shared library file with your app?

a. i'm not sure that can be done (with any effect anyway)
b. additional libraries would normally be installed separately unless an installer/package is being used
0
 
wjh7554Author Commented:
object, CEHJ, the *.so file were included in the .war file. I mistake previously overlook for that.

Now i am curious on this line of code:

private static final String MC_LIB_NAME = "readArray";  //mc tool library used for forming matrices

String strLibPath="/ABC/Tomcat/webapps/abc/WEB-INF/lib/";
System.setProperty("LD_LIBRARY_PATH", strLibPath);
System.setProperty("java.library.path", strLibPath);      
System.loadLibrary(MC_LIB_NAME); //loading mc library

//System.load("/usr/ABC/Tomcat/webapps/abc/WEB-INF/lib/libmc.so");
//System.load("/usr/ABC/Tomcat/webapps/abc/WEB-INF/lib/libreadArray.so");
//System.load("/usr/ABC/Tomcat/webapps/abc/WEB-INF/lib/libgmeans.so");

As you can see, the directory of the library is within "abc" directory and the filename called libreadArray.so

I didnt set <MC_LIB_NAME = "readArray";  > because "lib" of "libreadArray.so" is the prefix of it an dnot necessary to put it.

Thus, my question is, in term of java coding. Am i writting it correct?

private static final String MC_LIB_NAME = "readArray";  //mc tool library used for forming matrices
System.loadLibrary(MC_LIB_NAME); //loading mc library


0
 
wjh7554Author Commented:
if i change the code to be like this:

private static final String MC_LIB_NAME = "libreadArray.so";
System.loadLibrary(MC_LIB_NAME); //loading mc library


I will have this problems:

java.lang.UnsatisfiedLinkError : no libReadArray.so in java.library.path

and within the java.library.path ("/ABC/Tomcat/webapps/abc/WEB-INF/lib/") there is a file call libReadArray.so there. :-(
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Might be case-sensitive?
0
 
CEHJCommented:
>>private static final String MC_LIB_NAME = "libreadArray.so";

should be

private static final String MC_LIB_NAME = "libreadArray";

There should be no file extension
0
 
CEHJCommented:
... and yes, it most certainly *is* case-sensitive
0
 
objectsCommented:
> if i change the code to be like this:

Didn't see any need to change your code, what you had was fine.

> System.setProperty("LD_LIBRARY_PATH", strLibPath);
> System.setProperty("java.library.path", strLibPath);    

don't think you can set it at runtime, you need to set it before starting tomcat
eg. as I mentioned earier, or -Djava.library.path=/ABC/Tomcat/webapps/abc/WEB-INF/lib/ in CATALINA_OPTS

0
 
wjh7554Author Commented:
guys.. really appreciate your time and effort.

I have done some sample testing, by creating a StandAlone application:

public void main(String [] args) {

System.loadLibrary("readArray);
System.out.println("Hello World");
}

and it's working fine.

But when i change my web application, with amended code to be like this:

//private static final String MC_LIB_NAME = "readArray";  //mc tool library used for forming matrices

//String strLibPath="/ABC/Tomcat/webapps/abc/WEB-INF/lib/";
//System.setProperty("LD_LIBRARY_PATH", strLibPath);
//System.setProperty("java.library.path", strLibPath);    
System.loadLibrary("readArray); //loading mc library

I will still have this problems.

java.lang.UnsatisfiedLinkError: readArray
      com.netra.cluster.callnative.readArray(Native Method)
      com.netra.cluster.callnative.ClusterFS(callnative.java:259)
      com.netra.servlet.ClusterServlet.doGet(ClusterServlet.java:84)
      com.netra.servlet.ClusterServlet.doPost(ClusterServlet.java:103)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Thus, environemnt wise am confidence i have set it up successfully. Is tomcat required any additional setup for Java Native Call?

this the callnative.java:259
>>       int i = new callnative().readArray(cluster_args, IndexFilePath, IndexCount);//calling native method from mc

ClusterServlet.java:84
>> clsCallNative.ClusterFS(profile_id, strUID.toString());

Is tomcat required any additional setup for Java Native Call?
0
 
CEHJCommented:
Check Tomcat logs for library loading errors. You may need to tweak the SecurityManager to allow that
0
 
wjh7554Author Commented:
i didnt see any special note in the log file of tomcat. The catalina.out didnt show anything. And below is my localhost_log_2006-06-28.txt file.


2006-06-28 03:57:47 StandardContext[/servlets-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1dddba')
2006-06-28 03:57:47 StandardContext[/servlets-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@c7e8a7')
2006-06-28 03:57:47 StandardContext[/servlets-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@7b4703')
2006-06-28 03:57:47 StandardContext[/servlets-examples]SessionListener: contextDestroyed()
2006-06-28 03:57:47 StandardContext[/servlets-examples]ContextListener: contextDestroyed()
2006-06-28 03:57:47 StandardContext[/jsp-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1071521')
2006-06-28 03:57:47 StandardContext[/jsp-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1fc3c84')
2006-06-28 03:57:47 StandardContext[/jsp-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@e93999')
2006-06-28 03:57:47 StandardContext[/jsp-examples]SessionListener: contextDestroyed()
2006-06-28 03:57:47 StandardContext[/jsp-examples]ContextListener: contextDestroyed()
2006-06-28 06:51:13 StandardContext[/balancer]org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
2006-06-28 06:51:13 StandardContext[/jsp-examples]ContextListener: contextInitialized()
2006-06-28 06:51:13 StandardContext[/jsp-examples]SessionListener: contextInitialized()
2006-06-28 06:51:13 StandardContext[/servlets-examples]ContextListener: contextInitialized()
2006-06-28 06:51:13 StandardContext[/servlets-examples]SessionListener: contextInitialized()
2006-06-28 06:51:18 StandardContext[/manager]HTMLManager: init: Associated with Deployer 'localhost'
2006-06-28 06:51:18 StandardContext[/manager]HTMLManager: init: Global resources are available
2006-06-28 06:51:18 StandardContext[/manager]HTMLManager: list: Listing contexts for virtual host 'localhost'
2006-06-28 06:51:27 StandardWrapperValve[ClusterServlet]: Servlet.service() for servlet ClusterServlet threw exception
java.lang.UnsatisfiedLinkError: readArray
      at com.netra.cluster.callnative.readArray(Native Method)
      at com.netra.cluster.callnative.ClusterFS(callnative.java:259)
      at com.netra.servlet.ClusterServlet.doGet(ClusterServlet.java:84)
      at com.netra.servlet.ClusterServlet.doPost(ClusterServlet.java:103)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
      at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Thread.java:595)
0
 
CEHJCommented:
You need to be able to prove, from inside your web app, the value of $LD_LIBRARY_PATH. Can you print it?
0
 
objectsCommented:
the problem is not with loading your library, it is with the library itself by the look of it. check you have created it correctly.
Try changing your test app to actually call one of the native methods provided by the library.
0
 
wjh7554Author Commented:
CEHJ, how you want me to prove it. I manage to doa echo in the catalina.sh when the tomcat started, i manage to see the library file stored in [CATALINA_HOME]/webapps/ABC/classes/lib

or shall i put it in [Catalina_home]/shared/lib and [catalina_home]/common/lib?

object, ok. will try to call the method within the libreadArray.so file.
0
 
objectsCommented:
> or shall i put it in [Catalina_home]/shared/lib and [catalina_home]/common/lib?

where you have it already is fine, there is no need to move it

0
 
wjh7554Author Commented:
ok. object. let me try to access the code within the .so file and get back to you.
0
 
CEHJCommented:
>>CEHJ, how you want me to prove it.

Actually it would be better to see if it *is* loaded. Use

lsmod
0
 
objectsCommented:
Its already been shown that it is loaded.
0
 
wjh7554Author Commented:
CEHJ, Object. this is my latest finding. As per explained, the standlaone java application able to load the .so library files. It's proved.

But when its run on the web Application, previously i thought it's throwing the error in here;

System.loadLibrary("readArray); //loading mc library

but after i add a System.out.println before and after this line, it's able to print out. [ sorry as i am so stupid to perform this test before]. Thus, i guest the error is not the loading part of the library. So, i trace back the StackTrace;

java.lang.UnsatisfiedLinkError: readArray
     com.netra.cluster.callnative.readArray(Native Method)
     com.netra.cluster.callnative.ClusterFS(callnative.java:259)
     com.netra.servlet.ClusterServlet.doGet(ClusterServlet.java:84)
     com.netra.servlet.ClusterServlet.doPost(ClusterServlet.java:103)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

i notice in this line, [com.netra.cluster.callnative.ClusterFS(callnative.java:259)] , i have this line of code;  
int i = new callnative().readArray(cluster_args, IndexFilePath, IndexCount);//calling native method from mc

So, now this time i am sure this is the problem error place. instead of testing this in the system, i decided to create a new project with a simple servlet to test is it working..

Thus, below is the code (servlet) that i have completed. AND AGAIN IT'S STILL THROWING ME THE SAME ERROR. * this time i didnt passed any parameter instead of calling the method directly. *

package srvlt;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import socall.*;

@SuppressWarnings("serial")
public class sosrvlt extends HttpServlet{

      private static HelloWorld hlwrld;
      
      public void doGet(HttpServletRequest request,HttpServletResponse response)
      throws IOException, ServletException {
                  try {
                        
                              hlwrld= new HelloWorld();
                              System.out.println("sosrvlt");
                              hlwrld.Myfunction();
                              
                  }
                  catch(Exception e){
                        e.printStackTrace();      
                  }
      }

      public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
            doGet(request, response);
      }

}
                        

For your information, the library of libreadArray is my custom make library. This is the way i am compling it and pack as .so file. Is this the correct way? any extra parameter i should used?

gcc  temp.c -o libHello.so -shared -I/usr/local/jdk1.5/include -I/usr/local/jdk1.5/include/freebsd

I still didnt able to figure out why it's happend in web application and not standalone application.
0
 
wjh7554Author Commented:
the LIB_LIBRARY_PATH Is set in the environemtn separately...
0
 
objectsCommented:
> Thus, i guest the error is not the loading part of the library

mentioned that above

the problems either in the sigs in your native code or how you are building the jni dll.
can you post your native code
0
 
wjh7554Author Commented:
object, sorry for the late reply.. below is my details program that is involved in the testing. and i also share the native code along..


package srvlt;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import socall.*;

@SuppressWarnings("serial")
public class sosrvlt extends HttpServlet{

     private static HelloWorld hlwrld;
     
     public void doGet(HttpServletRequest request,HttpServletResponse response)
     throws IOException, ServletException {
               try {
                   
                         hlwrld= new HelloWorld();
                         System.out.println("sosrvlt");
                         hlwrld.Myfunction();
                         
               }
               catch(Exception e){
                    e.printStackTrace();    
               }
     }

     public void doPost(HttpServletRequest request, HttpServletResponse response)
     throws IOException, ServletException {
          doGet(request, response);
     }

}

*********************
package socall;

public class HelloWorld {
      
      public native int displayHelloWorld();
      
      static {
            System.loadLibrary("Hello");
      }
      
      //public static void main(String[] args) {
      public void Myfunction() throws Exception{
            try{
                  int i=new HelloWorld().displayHelloWorld();
                  System.out.println("From Java: " + i);
            }catch(Exception e){
                  e.printStackTrace();
            }
      }
}
                        
****************
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>

JNIEXPORT int JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
      printf("\nHello to Java.\n");
      return 1;
}

**
The way i packed my HelloWorldImp.c to .so file is witht his command:

gcc  HelloWorldImp.c -o libHello.so -shared -I/usr/local/jdk1.5/include -I/usr/local/jdk1.5/include/freebsd

**
Anything you can sense is not right? or is it that normal you do for JNI Calling?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 13
  • 11
  • 7
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now