simple mapserver instrucctions don't work!!

Dan Barron dbarron at DSWLLC.COM
Wed Dec 1 11:32:59 EST 2004


Jose,

I understand your frustration having gone through this not so long ago
myself.  Be sure to read all the previous threads on the subject as well.

OK, from what I understand, there are a few things to check and pardon me
if I am too verbose or do not have enough information on "why" these items
are necessary. I am assuming you are using tomcat on some sort of U/Linux
platform.

1) The java class that loads the mapscript library or the jar file that
includes the class that loads the library must be in the
<tomcat-root>/common/lib directory.

   for example: the jar file I is use - dswllc-mapscript.jar - that has the
JavaMapscript.class (which is shown below and loads the mapscript library)
is located in my <tomcat-root>/common/lib directory

2) As stated in previous threads, you *cannot* have the java class that
loads the mapscript library in the <web-app-root>/WEB-INF/classes
directory.  And you cannot have a jar file that includes the class that
loads the library in the <web-app-root>/WEB-INF/lib directory.

   for example: I could not place the above mentioned files in my
<web-app-root>/WEB-INF/lib or <web-app-root>/WEB-INF/classes directories or
I would get the "Library already loaded" error.

3) The mapscript.jar file created when compiling the java mapscript for
Mapserver can also be in the <tomcat-root>/common/lib directory (if you
want it available to all web apps under Tomcat), or in your
<web-app-root>/WEB-INF/lib directory.  This is the jar file created when
you run make in the <mapserver-src-root>/mapscript/java
directory.  Essentially once you run make in the
<mapserver-src-root>/mapscript/java directory your should copy the
mapscript.jar file to the <tomcat-root>/common/lib or your
<web-app-root>/WEB-INF/lib directory and the libmapscript.so file to a
location the system knows to look for libraries - such as /usr/local/lib

   for example: In my configuration I copy the mapscript.jar file to my
<tomcat-root>/common/lib directory and my libmapscript.so file to
/usr/local/lib/special

4) You should set your environment variable  LD_LIBRARY_PATH to the include
the path the to libmapscript.so and/or edit your /etc/lib.so.conf file to
include the path to the llibmapscript.so file - or just place it in a
directory the system already knows to look for libraries - such as
/usr/local/lib

Hope that helps.

Dan


At 07:11 AM 12/1/2004, Jose Luis Gonzalez wrote:
>I am working in java, with servlets. I can be able to load the library (I
>think) but Its says that another class had already loaded it, because even
>using the program you propose me it gives me an UnsatisfiedLinkError.
>The great problem is that I can not acceed to the mapserver objects as you
>say.
>I think the libmapserver.so is not in the correct place.And I included it
>in the path, but it seems he doesn't get it.
>So if you have any sugestions please tell me.
>
>thank you
>
>Jose Luis
>
>n Barron <dbarron at dswllc.com> wrote:
>Jose Luis,
>
>What is your scenario again?  You can load the mapscript library - and
>prove it is loaded?  Then you cannot create any mapserver objects?
>
>Please try to use the following files for a simple test.  The first file
>is the java object that loads the libmapscript.so.  The second is simple
>jsp file that can be used to create an instance of JavaMapscript, then
>just print out its version info.
>
>Dan
>
> >>~~~~~~~~~ File - JavaMapscript.java ~~~~~~~~~~~~~~~~<<
>
>package edu.umn.gis.java.mapscript;
>
>/**
>  * Created by user: umberto at unicolet.org
>  * Date: May 23, 2004
>  * License: GPL
>  */
>
>public class JavaMapscript {
>
>     private static JavaMapscript instance = null;
>
>     private JavaMapscript() {
>         try {
>             System.loadLibrary("mapscript");
>         } catch (Exception e) {
>             e.printStackTrace();
>             System.err.println("* error loading native library *");
>             System.err.println("Error is: "+e);
>         }
>         System.out.println(" * mapscript native library loaded *");
>     }
>
>     public static JavaMapscript getInstance() {
>         if ( instance == null ) {
>             instance = new JavaMapscript();
>         }
>         return instance;
>     }
>}
>
>
> >>~~~~~~~~ FILE - test-mapsctipt.jsp ~~~~~~~~~<<
>
><%@ page import="edu.umn.gis.mapscript.*"%>
><%
>     out.print("<br/>loading mapscript library...<br/>");
>
>   /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    * Load the libmapscript.so native library just once
>    * JavaMapscript class will ensure it is only loaded once
>    *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
>    edu.umn.gis.java.mapscript.JavaMapscript.getInstance();
>
>     out.print("<br/>mapscript library loaded sucessfully...<br/>");
>
>    mapscript ms = new mapscript();
>
>     out.print("<br/>mapscript library version: " + ms.msGetVersion() +
> "<br/>");
>
>%>
>
>At 08:11 AM 11/30/2004, Jose Luis Gonzalez wrote:
>
>>I have wrote this email to the mapserver mailing list, and I do not
>>obtain any solution. I think you had a similar problem, so could you help
>>me please.
>>I think it could be the libmapscript.so that is not locolized, but it
>>apears correctly in the paths of my server...so I don't know what is the
>>problem.(I send you how the paths are set in a .jpg file)
>>
>>Thank you
>>
>>Jose Luis
>>
>>p.d. I have tried with different mapserver instructions like mapObj map =
>>new mapObj("test.map"); and I always obtain the same error.
>>I am using mapserver 4.2.4.
>>All I wanted to do is to do any simple mapserver instructions to see that
>>everything works.
>>I have tried the demos that apear when you install mapserver, but I
>>wanted to see it work with my own code and deploying my archives to the
>>server.
>>For example it will be great if i could manage to just draw a .map file
>>for instance as a response to the client.
>>Do you now how to do this, or what easy instrctions I can use to see if
>>it works?
>>
>>Thank you
>>
>>Jose Luis
>>n Gillies <sgillies at FRII.COM> wrote:
>>On Nov 29, 2004, at 4:26 AM, Jose Luis Gonzalez wrote:
>> > --0-82611386-1101727598=:30831
>> > Content-Type: text/plain; charset=iso-8859-1
>> > Content-Transfer-Encoding: 8bit
>> >
>> > This is my code:
>> > First of all I have this file:
>> >
>> > package javamaps;
>> >
>> > public class MapserverLibLoad{
>> > public static void loadLibrary() throws UnsatisfiedLinkError{
>> > System.loadLibrary("mapscript");
>> > }
>> > }
>> >
>> > Then this is the principal program, as you see it is a servlet:
>> >
>> > import javamaps.*;
>> > import edu.umn.gis.mapscript.*;
>> > import javax.ejb.*;
>> > import javax.xml.parsers.*;
>> > import javax.xml.transform.*;
>> > import javax.xml.transform.dom.*;
>> > import org.w3c.dom.*;
>> > import java.sql.*;
>> > import javax.sql.*;
>> > import javax.naming.*;
>> >
>> > import javax.servlet.*;
>> > import javax.servlet.http.*;
>> > import java.io.*;
>> > public class test2 extends HttpServlet{
>> >
>> > InitialContext initialContext=null;
>> >
>> > static{
>> > try{
>> > MapserverLibLoad.loadLibrary();
>> > }catch(UnsatisfiedLinkError e){
>> > e.printStackTrace();
>> > System.out.println("CONTINUE");
>> > }
>> > }
>> >
>> >
>> > /
>> > /----------------------------------------------------------------------
>> > ------------------------------------------------------
>> >
>> > private Connection createDatabaseConnection()throws EJBException{
>> > DataSource dataSource;
>> > Connection connection;
>> > PreparedStatement stmt;
>> > try{
>> > dataSource = (DataSource) initialContext.lookup("jdbc/lbs");
>> > connection= dataSource.getConnection();
>> > //System.out.println("
>> > DATABSE:::::"+connection.getMetaData().getUserName());
>> > return connection;
>> > }catch (SQLException e){
>> > throw (new EJBException(e));
>> > }catch (NamingException e){
>> > throw (new EJBException(e));
>> > }
>> > }
>> >
>> >
>> >
>> > /
>> > /----------------------------------------------------------------------
>> > ------------------------------------------------------
>> > public void init (ServletConfig cfg){
>> > try{
>> > System.out.println("Try to init servlet");
>> > System.out.flush();
>> > initialContext= new InitialContext();
>> > }catch(Exception e){
>> > throw (new EJBException(e));
>> > }
>> >
>> > }//fin init
>> >
>> > public void service (HttpServletRequest req, HttpServletResponse res){
>> > Connection conexion=null;
>> > String imei=null;
>> > PrintWriter out=null;
>> > Statement orden=null;
>> > ResultSet rs=null;
>> > String SQL=null;
>> >
>> > try{ itemObj item = new itemObj();
>> > System.out.println(" BIG NAME
>> > :>>"+item.getName()+"<<");
>> >
>> > conexion=this.createDatabaseConnection();
>> > imei=req.getParameter("IMEI");
>> > out=res.getWriter();
>> > SQL="SELECT * FROM Client WHERE Name=";
>> > SQL=SQL+"'"+imei+"'";
>> > orden=conexion.createStatement();
>> > rs=orden.executeQuery(SQL);
>> > res.setContentType("text/html");
>> > out.println("");
>> > out.println(" ");
>> > rs.next();//I move to the first row
>> > out.println("
>>");
>> > out.println("
>>");
>> > out.println("
>>"+rs.getString("Name"));
>> > out.println(" "+rs.getString("Mobile"));
>> >
>> > out.println(" "+rs.getString("Telephone_Number"));
>> > out.println("
>>");
>> > while (rs.next()){
>> > out.println("
>>"+rs.getString("Name"));
>> > out.println(" "+rs.getString("Mobile"));
>> >
>> > out.println(" "+rs.getString("Telephone_Number"));
>> > out.println("
>>");
>> > }
>> > out.println("");
>> >
>> >
>> >
>> > }//fin try
>> > catch (Exception e){
>> > System.out.println(e);
>> > }catch (Throwable e){
>> > System.out.println("WRONGG POINT");
>> > e.printStackTrace();
>> > }finally{
>> > try{
>> > out.close();
>> > rs.close();
>> > conexion.close();
>> > orden.close();
>> > }catch(Exception e){
>> > throw (new EJBException(e));
>> > }
>> >
>> > }//fin service
>> >
>> > }
>> > }
>> >
>> > It seems as like he can't reach the mapserver librarys and I don't
>> > know why.It gives me this error:
>> >
>> > java.lang.UnsatisfiedLinkError: new_itemObj
>> >
>> > Can someone help me?
>> > Know what I'm doing wrong?
>> >
>> > Thank you
>> >
>> > Jose Luis
>> >
>>Jose Luis,
>>1) it is *very* important that you mention which version of MapServer
>>you use! The mapscript module has changed very much from 3.6 to 4.4.
>>2) do not try to use itemObj, it is not functional. We use SWIG to
>>generate the mapscript wrapper for Java, and it is very permissive,
>>with the result that non-functional classes can be accidently
>>added to mapscript. I'm going to shut itemObj out of the final 4.4
>>release.
>>cheers,
>>Sean
>>
>>
>>--
>>Sean Gillies
>>sgillies at frii dot com
>>http://users.frii.com/sgillies
>>
>>
>>
>><http://es.rd.yahoo.com/mail_es/tagline/mail/image/*http://es.mail.yahoo.com>
>>Nuevo Correo Yahoo!
>>
>>
>>
>>
>><http://es.rd.yahoo.com/mail_es/tagline/mail/image/*http://es.mail.yahoo.com>
>>Nuevo Correo Yahoo!
>
>
>
><http://es.rd.yahoo.com/mail_es/tagline/mail/image/*http://es.mail.yahoo.com>
>Nuevo Correo Yahoo!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20041201/5dcebe32/attachment.html


More information about the mapserver-users mailing list