<html>
<body>
Jose,<br><br>
Here's what works well for me and can be used in a servlet or any jsp
file - courtesy of Umberto btw.<br><br>
1) >> file JavaMpascript.java <<<br><br>
package mapserver.java.mapscript;<br><br>
/**<br>
* Created by user: umberto at unicolet.org<br>
* Date: May 23, 2004<br>
* License: GPL<br>
*/<br><br>
public class JavaMapscript {<br>
<br>
private static JavaMapscript instance =
null;<br><br>
private JavaMapscript() {<br>
try {<br>
System.loadLibrary("mapscript");<br>
} catch (Exception e) {<br>
e.printStackTrace();<br>
System.err.println("* error loading native library *");<br>
System.err.println("Error is: "+e);<br>
}<br>
System.out.println(" *
mapscript native library loaded *");<br>
}<br><br>
public static JavaMapscript getInstance() {<br>
if ( instance == null )
{<br>
instance = new JavaMapscript();<br>
}<br>
return instance;<br>
}<br>
} <br><br>
2) >> Make an instance of this class somewhere else.<br><br>
mapserver.java.mapscript.JavaMapscript.getInstance();<br><br>
Your library will only be loaded once, at least that is how it behaves
for me and has been reliable so far.<br><br>
Dan<br><br>
<br>
At 06:34 AM 11/24/2004, Chris wrote:<br>
<blockquote type=cite class=cite cite><font face="arial" size=2 color="#0000FF">Jose,
what servlet container are you using?<br>
</font> <br>
<font face="arial" size=2 color="#0000FF">Try initializing the servlet
first without calling it -- you can do this by putting it in web.xml like
this:<br>
</font> <br>
<font face="arial" size=2 color="#0000FF"><servlet><br>
</font>
<font face="arial" size=2 color="#0000FF"><servlet-name>test</servlet-name><br>
</font>
<font face="arial" size=2 color="#0000FF"><servlet-class> {your
class name} </servlet-class><br>
<load-on-startup>1</load-on-startup><br>
</servlet><br>
</font><br>
<font face="arial" size=2 color="#0000FF">This will force the init() to
run without the service(). Also you should avoid lazy
initialization in Singleton classes. <br>
</font><br>
<font face="arial" size=2 color="#0000FF">Regards,<br>
</font><br>
<font face="arial" size=2 color="#0000FF">Chris<br>
</font>
<dl>
<dd><font face="tahoma" size=2>-----Original Message-----<br>
<dd>From:</b> Jose Luis Gonzalez
[<a href="mailto:joseluismapserver@YAHOO.ES" eudora="autourl">mailto:joseluismapserver@YAHOO.ES</a>]<br>
<dd>Sent:</b> Wednesday, November 24, 2004 4:51 AM<br>
<dd>To:</b> MAPSERVER-USERS@LISTS.UMN.EDU<br>
<dd>Subject:</b> Re: [UMN_MAPSERVER-USERS] mapserver java
servlets<br><br>
</font>
<dd>Hi Oliver,<br>
<dd>I have just done what you recomended, leaving the
JavaMapscript-Class so the only thing he does is to load the
library.<br>
<dd>Then in another class, the one where I have my servlet, I wote in
the: public void init (ServletConfig cfg){<br>
<dd> <br>
<dd>JavaMapscript.getInstance();<br>
<dd> <br>
<dd>and later in the:<br>
<dd>public void service (HttpServletRequest req, HttpServletResponse
res){<br>
<dd> <br>
<dd>I began writing my mapscript code, and it still gives me the same
error:<br>
<dd> <br>
<dd>javax.servlet.ServletException: Native Library
/opt/SUNappserver/domains/domain1/lib/ext/libmapscript.so already loaded
in another classloader<br>
<dd> <br>
<dd>Do you know why?<br>
<dd> <br>
<dd>Thank you<br>
<dd> <br>
<dd>Jose Luis<br><br>
<dd>Oliver Wesp <wesp@gdv.com></i></b> wrote:<br>
<dd>Hi,<br><br>
<dd>you're on the right way to avoid the "Native library cannot be
loaded <br>
<dd>twice" error. Your JavaMapscript-Class implements a singleton so
it's <br>
<dd>loaded only once in Tomcat. But you should not add your mapscript
code <br>
<dd>to this class. Whenever you change the class Tomcat tries to reload
and <br>
<dd>complains about the library already loaded.<br>
<dd>Write a second class and load the library with<br><br>
<dd>JavaMapscript.getInstance();<br><br>
<dd>Add your mapscript code to that class and you should be
fine.<br><br>
<dd>best regards<br>
<dd>Oliver<br><br>
<dd>Jose Luis Gonzalez wrote:<br>
<dd>> Hi to all<br>
<dd>> I would implement mapserver in tomcat as servlet but I have
found a lot of<br>
<dd>> problems in start with it!<br>
<dd>> <br>
<dd>> So:<br>
<dd>> 1) is there sites that implement mapserver as servlet in tomcat
that I can<br>
<dd>> view?<br>
<dd>> 2) Some one have a piece of basic code that I can compile as
servlet in<br>
<dd>> tomcat for view how it run? I have load the java Howto.<br>
<dd>> <br>
<dd>> Do you have examples so I can see how can I work<br>
<dd>> with mapserver functions and servlets?<br>
<dd>> I have been seeing the wiki, but I can not really find what I
want.<br>
<dd>> <br>
<dd>> I have done the example of loading a library that apears
in:<br>
<dd>> <br>
<dd>>
<a href="http://www.unicolet.org/mapserver/tomcat.html" eudora="autourl">http://www.unicolet.org/mapserver/tomcat.html</a>
<br>
<dd>> <br>
<dd>> <br>
<dd>> and it works, but when I want to complete the JavaMapscript.java code <br>
<dd>> with other<br>
<dd>> mapserver comands, it doesn't work:<br>
<dd>> <br>
<dd>> import edu.umn.gis.mapscript.*;<br>
<dd>> <br>
<dd>> public class JavaMapscript {<br>
<dd>> private static JavaMapscript instance=null;<br>
<dd>> <br>
<dd>> private JavaMapscript() {<br>
<dd>> try {<br>
<dd>> System.loadLibrary("mapscript");<br>
<dd>> } catch (Exception e) {<br>
<dd>> e.printStackTrace();<br>
<dd>> System.err.println("* error loading native library *");<br>
<dd>> System.err.println("Error is: "+e);<br>
<dd>> }<br>
<dd>> System.out.println(" * mapscript native library loaded *");<br>
<dd>> mapObj map = new mapObj("test.map");<br>
<dd>> imageObj img = map.draw();<br>
<dd>> //img.save("result", map);*/<br>
<dd>> }<br>
<dd>> <br>
<dd>> public static JavaMapscript getInstance() {<br>
<dd>> System.out.println("Try to instantiate Mapscript");<br>
<dd>> System.out.flush();<br>
<dd>> if ( instance == null ) {<br>
<dd>> instance = new JavaMapscript();<br>
<dd>> }<br>
<dd>> return instance;<br>
<dd>> }<br>
<dd>> }<br>
<dd>> <br>
<dd>> And even worse, when I do any modifications and I put the new .class <br>
<dd>> file in the<br>
<dd>> server, I have an error because it says that the library was already <br>
<dd>> loaded, and<br>
<dd>> my only solution now to solve it is to turn off the server and turn it <br>
<dd>> on again.<br>
<dd>> <br>
<dd>> Hope someone can help me<br>
<dd>> <br>
<dd>> Thank you<br>
<dd>> <br>
<dd>> Jose Luis<br>
<dd>> <br>
<dd>> ------------------------------------------------------------------------<br>
<dd>> <br>
<dd>> Nuevo Correo Yahoo! <br>
<dd>> <br>
<dd>> <br><br>
<br>
<dd>-- <br>
<dd>Dipl.-Geogr. Oliver Wesp<br>
<dd>Gesellschaft fuer geografische Datenverarbeitung<br>
<dd>Binger Strasse 49-51<br>
<dd>D-55218 Ingelheim<br>
<dd>fon: +49 6132 714818<br>
<dd>fax: +49 6132 714828<br>
<dd>http: <a href="http://www.gdv.com/" eudora="autourl">www.gdv.com</a><br><br>
</dl><br>
<br>
<a href="http://es.rd.yahoo.com/mail_es/tagline/mail/image/*http://es.mail.yahoo.com"><img src="http://eur.i1.yimg.com/eur.yimg.com/i/es/mail/mails.gif" width=230 height=80 alt="Nuevo Correo Yahoo!"></a><br>
</blockquote></body>
</html>