[mapserver-users] Mapscript/Java

Sathiskumar Govindasamy gsathis at hashprompt.com
Fri Jun 21 11:39:01 EDT 2002


  Isabelle,

The following is a mail that I have written to mapserver-users group a 
while ago. I believe it might help. Also there is an example java 
program of how to use it.

Thanks
Sathis

This is what I did.

I got the mapserver source code and untarred it and did the following

./configure --with-jpeg --with-gd --with-proj 
--with-gdal=/usr/local/bin/gdal-config
make

Then I got the SWIG Version 1.3.11 source.

./configure --with-javac=/usr/java/j2sdk1.4.0/bin/ 
--with-java=/usr/java/j2sdk1.4.0/bin/ 
--with-javaincl=/usr/java/j2sdk1.4.0/include/
make
make install

I created a directory called java in mapserver-src/mapscript and created 
a symlink for mapscript.i inside it.  (In the new nightly builds, you 
might not need this step since it should be already in there)

/usr/local/bin/swig -java -shadow -package mapscript mapscript.i

It created some java files.
Then I did
FLAGS="-DUSE_PROJ -DUSE_PROJ_API_H -DUSE_GD_PNG -DUSE_GD_JPEG 
-DUSE_GD_WBMP -DUSE_GD_FT -DUSE_WMS -DUSE_TIFF -DUSE_JPEG -DUSE_EPPL 
-DUSE_GDAL"gcc -fpic -c $FLAGS -I/usr/java/j2sdk1.4.0/include 
-I/usr/java/j2sdk1.4.0/include/linux mapscript_wrap.c
gcc -fpic -shared -o libmapscript.so -L/usr/lib -lgd -ljpeg -lfreetype 
-lpng -lz -ltiff  -L/usr/local/lib -lgdal.1.1 -lproj mapscript_wrap.o 
../../libmap.a


Java programs didn't compile right off the bat. I need to correct all 
those 'long' variable types and return types. Then it compiled. (New 
nightly build should compile clean)

In tomcat, I added the following line in /etc/tomcat4/conf/tomcat4.conf

export LD_LIBRARY_PATH=/opt/mapserver/mapscript/java:$LD_LIBRARY_PATH

I have the mapserver installed on /opt/

I have attached a servlet sample .

Thanks
Sathis

------------------------------------------------------------------------

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

import mapscript.*;

public class demo extends HttpServlet
{
	static
	{
		try
		{
			System.loadLibrary("mapscript");
			System.err.println("Loaded the Mapscript library");
		}
		catch (UnsatisfiedLinkError e)
		{
			e.printStackTrace();
		}
	}

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
	throws ServletException, IOException
	{
		
		System.err.println("doGet Method Accessed");
		String strTruckID = req.getParameter("trucklocid");

		mapObj map = new mapObj("/var/tomcat4/webapps/fleetmanager/nationalatlas/demo.map");
		long image = map.prepareImage();

		layerObj layerstate = map.getLayerByName("statesp020");
		layerstate.draw(map.getCPtr(),image);

		layerObj layerroad = map.getLayerByName("roadtrl020");
		layerroad.draw(map.getCPtr(),image);

		layerObj layerwater= map.getLayerByName("hydrogp020");
		layerwater.draw(map.getCPtr(),image);

		layerObj layercities= map.getLayerByName("cities");
		layercities.draw(map.getCPtr(),image);

		String filename = "temp/temp.jpg"

		//msSaveImage(img,filename,type,transparent,interlace,quality)
		mapscript.msSaveImage(image,"/var/tomcat4/webapps/fleetmanager/"+filename,map.getImagetype(),
					map.getTransparent(),map.getInterlace(),map.getImagequality());

		resp.sendRedirect(filename);


	}
	
}



Isabelle KERVELLA wrote:

>In the documentation there is mentioned that the MapServer system
>supports MapScript which allows Java to access the MapServer C API.
>
>The MapServer 3.6 distribution includes PHP/Mapscript. But where can I
>find Java/Mapscript for Windows and Unix ?
>
>Or, is it possible to easily generate a java version of MapScript ?
>
>Thanks for any help,
>
>Isabelle
>  
>





More information about the mapserver-users mailing list