0

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.

Vish
  • 832
  • 7
  • 21

2 Answers2

3

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.

Luke Woodward
  • 63,336
  • 16
  • 89
  • 104
0

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!

buruzaemon
  • 3,847
  • 1
  • 23
  • 44
  • ya that I have done. Even I did the second one also, but problem is that, I didnt find any file with name libmapscript.so anywhere in installation of mapserver and in root (/ of ubuntu). While refreshing the browser the UnsatisfiedLinkError is disappeared and I am getting ony NoClassDefFoundError. – Vish Dec 10 '11 at 11:28
  • `libmapscript.so` should have been created in your compile step on your Linux server. Could you post your `configure` options? (c.f. http://trac.osgeo.org/mapserver/wiki/JavaMapscriptUsing#againstFwtools) – buruzaemon Dec 10 '11 at 11:31
  • I have done everything according to that post you have shared link as post. Just one thing we didnt do is, making and testing interface. Is that neccessary? – Vish Dec 10 '11 at 11:34
  • @Vish are you using `-Dmapserver.library.name`? Because if `libmapscript.so` is not on your system, your JVM cannot link to the mapscript code. – buruzaemon Dec 10 '11 at 11:43
  • I am new to Ubuntu. I have confusion regarding the word 'cofigure' and '-Dmapserver.library.name'. Can u explain it? I have installed mapserver in root directory and even FwTools-2.0.1 inside root. I found on that we have to set export 'LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/share/tomcat6/common/lib', for 'libmapscript.so' while browsing but after checking the complete system for this file, is in vain. – Vish Dec 10 '11 at 12:05
  • `configure` is the short script you would run to set your build options for mapscript. You would need to configure and compile mapscript for your target server; you cannot simply copy files over from a Windows machine and hope to have it run on Linux. Please read the document I linked above for `configure` and compile instructions on Linux first. The result of this is that you will then have the shared object that is the library for mapscript (libmapscript.so), fit for use on your Linux server. It sounds like you have yet to take this first step. – buruzaemon Dec 10 '11 at 12:18
  • Please tell me how to create 'libmapscript.so'. If possible provide me demo of 'configure'. 'configure: error: invalid variable name: --with-gdal ' as my configuration is './configure --enable-debug --with-threads --without-pdf --without-tiff \ --with-gdal=/FWTools2.0.6/bin/gdal-config --with-proj=/FWTools2.0.6/ \--with-gd=/FWTools2.0.6 --with-freetype=/FWTools2.0.6\ --with-png=/FWTools2.0.6 --with-zlib=/FWTools2.0.6 --with-jpeg=/FWTools2.0.6' – Vish Dec 12 '11 at 09:17
  • @Vish you understand now that the root of the problem in your question above is that you do not even have `libmapscript.so` compiled for your system. I am sorry, but the issue of configuring your build options options for your desired version of mapscript is a completely different question. My only suggestion at this point is that you take the time to read up on compiling mapserver on Unix (http://mapserver.org/installation/unix.html). – buruzaemon Dec 12 '11 at 14:10