UnsatisfiedLinkError and NoClassDefFoundError : Running Java Mapscript on Ubuntu 11.10

1.8k views Asked by At

We have coded and run a dynamic web application using MAPSERVER(Version 6.0.1) on windows platform using Java Technology. Now, there is need of deploying it on Ubuntu 11.10. We have installed Apache Tomcat 6.0, Mapserver 6.0.1, Apache 2.0, and FWTools-2.0.1(As this package contain all required tools for mapserver if I am not wrong, so I didn't feel any other tools to be installed). We have deployed the war file(and put application without) in Apache Tomcat 's Webapps folder. I even got the index page which dont have code related with mapscript api. But while fetching the other servlet with mapscript we are getting following error...

java.lang.UnsatisfiedLinkError: no mapscript in java.library.path
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
java.lang.Runtime.loadLibrary0(Runtime.java:840)
java.lang.System.loadLibrary(System.java:1047)
edu.umn.gis.mapscript.mapscriptJNI.<clinit>(mapscriptJNI.java:23)
edu.umn.gis.mapscript.mapObj.<init>(mapObj.java:283)

Again while refreshing the browser page where the above error was displayed, I got a change,

java.lang.NoClassDefFoundError: Could not initialize class    
edu.umn.gis.mapscript.mapscriptJNI
edu.umn.gis.mapscript.mapObj.<init>(mapObj.java:283)

I searched on net about the above problem. But finally blank. Please, provide idea about the above problem.

2

There are 2 answers

8
buruzaemon On

I would check the following 2 items:

  1. Is the mapscript.jar file on Tomcat or at least your webapp's classpath? (NoClassDefFoundError is your big clue here)
  2. Is the libmapscript.so on either your LD_LIBRARY_PATH or -Djava.library.path? (UnsatisfiedLinkError since the shared object cannot be found)

Try having a look at this post, near the Running Java Mapscript (on Linux) section.

Hope that helps!

2
Luke Woodward On

I'm not going to explain why you're getting the UnsatisfiedLinkError, but instead I'll explain why you are getting the NoClassDefFoundError when you reload the page.

A NoClassDefFoundError with a message Could not initialize class ... is thrown by the JVM when it attempts to initialize a class that it has already tried and failed to initialize.

The first of your two stacktraces contains the line

edu.umn.gis.mapscript.mapscriptJNI.<clinit>(mapscriptJNI.java:23)

The method name <clinit> denotes the static initializer, of the class mapscriptJNI. So, at the point that the UnsatisfiedLinkError was thrown, the JVM was trying to initialize this class. Looking at the error message, it seems that this static initializer tried to load the native code library mapscript but failed.

This UnsatisfiedLinkError causes the mapscriptJNI class to fail to initialize successfully. The JVM keeps a record of all classes that fail to initialize, and if you attempt to initialize one of those classes again, you'll get a NoClassDefFoundError with a message saying that it could not initialize that class.

When you refresh the page, you end up causing the JVM to attempt to initialize the class mapscriptJNI a second time. Of course, this class failed to initialize the previous time. Your second stacktrace contains exactly the error I've described.

In short, the UnsatisfiedLinkError is the real error here. Fix that and the other one will go away.