Solved

java.lang.UnsatisfiedLinkError

Posted on 2006-06-22
32
299 Views
Last Modified: 2007-12-19
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
Comment
Question by:wjh7554
  • 13
  • 11
  • 7
  • +1
32 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16958457
It needs to be on $LD_LIBRARY_PATH
0
 
LVL 92

Expert Comment

by:objects
ID: 16958458
put it somewher ein LD_LIBRARY_PATH, or add the directory it is in to that path
0
 

Author Comment

by:wjh7554
ID: 16966542
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
 

Author Comment

by:wjh7554
ID: 16966543
still giving me that error
0
 
LVL 92

Expert Comment

by:objects
ID: 16966558
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
 

Author Comment

by:wjh7554
ID: 16980908
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
 
LVL 92

Expert Comment

by:objects
ID: 16980928
> 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
 

Author Comment

by:wjh7554
ID: 16981174
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
 
LVL 92

Expert Comment

by:objects
ID: 16981197
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
 
LVL 92

Accepted Solution

by:
objects earned 170 total points
ID: 16981201
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16981657
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
 

Author Comment

by:wjh7554
ID: 16991566
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
 

Author Comment

by:wjh7554
ID: 16991681
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
 
LVL 30

Expert Comment

by:mayankeagle
ID: 16992221
Might be case-sensitive?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16996239
>>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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16996248
... and yes, it most certainly *is* case-sensitive
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 92

Expert Comment

by:objects
ID: 16996901
> 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
 

Author Comment

by:wjh7554
ID: 16999044
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16999052
Check Tomcat logs for library loading errors. You may need to tweak the SecurityManager to allow that
0
 

Author Comment

by:wjh7554
ID: 16999169
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16999194
You need to be able to prove, from inside your web app, the value of $LD_LIBRARY_PATH. Can you print it?
0
 
LVL 92

Expert Comment

by:objects
ID: 16999197
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
 
LVL 92

Expert Comment

by:objects
ID: 16999199
0
 

Author Comment

by:wjh7554
ID: 16999731
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
 
LVL 92

Expert Comment

by:objects
ID: 16999741
> 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
 

Author Comment

by:wjh7554
ID: 16999789
ok. object. let me try to access the code within the .so file and get back to you.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17005350
>>CEHJ, how you want me to prove it.

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

lsmod
0
 
LVL 92

Expert Comment

by:objects
ID: 17005801
Its already been shown that it is loaded.
0
 

Author Comment

by:wjh7554
ID: 17034599
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
 

Author Comment

by:wjh7554
ID: 17034604
the LIB_LIBRARY_PATH Is set in the environemtn separately...
0
 
LVL 92

Expert Comment

by:objects
ID: 17034622
> 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
 

Author Comment

by:wjh7554
ID: 17078527
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

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
wordcount challenge 11 78
Python Assistance 7 36
Strange loading of website behaviour 3 23
Java / Linux and Regular Expressions 11 48
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now