Fwd: Re: [mapserver-users] java MapScript

Scott Shealy sshealy at e811.com
Thu Dec 6 09:55:23 EST 2001


Hey guys this below is the email I sent to Stephen Lime when he asked me for 
more details about what I did.  It is sore of a hack and got me going... I 
think Stephen(correct me if I am wrong) is looking at intergrating these 
changes into the sourcecode and build process.  Ultimately though I think we 
need to figure out(It is on my list of things to do right now but not at the 
top) why the code that I ripped out is not compiling..

Hope this helps...

Scott Shealy

----------  Forwarded Message  ----------

Subject: Re: [mapserver-users] java  MapScript
Date: Wed, 5 Dec 2001 16:53:04 -0500
From: Scott Shealy <sshealy at e811.com>
To: "Stephen Lime" <steve.lime at dnr.state.mn.us>

I ripped out the following from the wrap file

---> Begin Code
static void _SWIG_exception(JNIEnv *jenv, int code, const char *msg) {
  char exception_path[512];
  const char *classname;
  const char *class_package = "java/lang";


  switch(code) {
  case SWIG_MemoryError:
    classname = "OutOfMemoryError";
    break;
  case SWIG_IOError:
    classname = "IOException";
    class_package = "java/io";
    break;
  case SWIG_SystemError:
  case SWIG_RuntimeError:
    classname = "RuntimeException";
    break;
  case SWIG_OverflowError:
  case SWIG_IndexError:
    classname = "IndexOutOfBoundsException";
    break;
  case SWIG_DivisionByZero:
    classname = "ArithmeticException";
    break;
  case SWIG_SyntaxError:
  case SWIG_ValueError:
  case SWIG_TypeError:
    classname = "IllegalArgumentException";
    break;
  case SWIG_UnknownError:
  default:
    classname = "UnknownError";
    break;
  }
  sprintf(exception_path, "%s/%s", class_package, classname);
  jclass excep;
  jenv->ExceptionClear();
  excep = jenv->FindClass(exception_path);
  if (excep)
  {
    jenv->ThrowNew(excep, msg);
  }
}
#define SWIG_exception(a,b) { _SWIG_exception(jenv, a,b); }
---->End Code

with things the way they are right now in the mapscript.i file SWIG_exception
is never called so removing this code removes no current functionality that I
am aware of.  It would be nice to have exceptions thrown into java for a
mapscript error though....(right now you can check return codes)  Actually if
someone ever has time it would be nice to have a  mapscipt.i file that was a
little more geared to java... I found that stroing some of the object
reference as longs in java was a little awarkward but did fine by me...

Also if you generate shadow classes you will have to go into them and rename
any methods getClass(...) to getClass_( or the java shadow classes will not
compile.



If you compile without ripping that function out you will get ....

mapscript_wrap.c: In function `_SWIG_exception':
mapscript_wrap.c:77: parse error before `excep'
mapscript_wrap.c:78: request for member `ExceptionClear' in something not a
structure or union
mapscript_wrap.c:79: `excep' undeclared (first use in this function)
mapscript_wrap.c:79: (Each undeclared identifier is reported only once
mapscript_wrap.c:79: for each function it appears in.)
mapscript_wrap.c:79: request for member `FindClass' in something not a
structure or union
mapscript_wrap.c:82: request for member `ThrowNew' in something not a
structure or union
gcc: mapscript_wrap.o: No such file or directory

It is complaining about the jclass excep line.... which on the surface looks
fine to me.... when time permits I am going to look at that closer...

I use this comand to swig

swig -java -shadow -package mapscript mapscript.i

I use the following script to compile my library

#!/bin/sh

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/jdk1.3.1_01/include
-I/usr/java/jdk1.3.1_01/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 mkdir javascript
mv *.java mapscript
javac -classpath ./ ./mapscript/*

Obviously the flags depends on how you compiled you mapserver and should be 
picked up from the mapserver make file....

Finally you need to take your libmapscript.so and put it somewhere where you
jdk will pick it up when you do a loadLibrary...

I know this is pretty crude but it got me going and that is all the boss
cares about right now....

Hope this helps... and thanks so much for being such an intergral part of a
wonderful program...

Scott Shealy

On Wednesday 05 December 2001 03:29 pm, Stephen Lime wrote:
> Can you descript the ripping out process a bit more. I'd like to make this
> more automated. Also. any sample scripts? Thanks.
>
> Steve
>
> Stephen Lime
> Data & Applications Manager
>
> Minnesota DNR
> 500 Lafayette Road
> St. Paul, MN 55155
> 651-297-2937
>
> >>> Scott Shealy <sshealy at e811.com> 12/05/01 09:41AM >>>
>
> I have gotten it to compile... I had to rip out the SWIG generated
> exception handeling code and rename all method that genrated the stub
> getClass(conflicts with java.lang.Object.getClass) to getClass_.  That did
> the trick. I think the SWIG genrated error code only handle C runtime
> exceptions so it is not that big a deal. I have been meaning to go back and
> see why it will not compile but I have not had a chance yet.. As I remember
> it was complaining about some jClass object(a JNI object) in the error
> handling code that look perfectly fine to me...
>
> Make sure when you compile it that you use all the same compiler flags that
> you compile the mapserver(libmap.a) with or you will have all kinds of fun
> runtime errors(related to memory errors)
>
> Scott Shealy

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



More information about the mapserver-users mailing list