Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a native library in Tomcat?

I want to add gdal library in Tomcat. I read Native libraries not found in Tomcat but don't understand where in startup.bat I should add -Djava.library.path.

Errors:

exception

javax.servlet.ServletException: Servlet execution threw an exception
com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)

root cause

java.lang.UnsatisfiedLinkError: org.gdal.ogr.ogrJNI.GetDriverCount()I
org.gdal.ogr.ogrJNI.GetDriverCount(Native Method)
org.gdal.ogr.ogr.GetDriverCount(ogr.java:98)
org.geotools.data.ogr.OGRDataStore.<clinit>(OGRDataStore.java:169)
test.Read.getKadnum(Read.java:56)
test.Zipper.mifUnzip(Zipper.java:139)
test.Zipper.Unzip(Zipper.java:60)
test.uploadfile.doPost(uploadfile.java:105)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.23 logs.

I downloaded gdal 64bit from: http://vbkto.dyndns.org:1280/sdk/PackageList.aspx?file=release-1600-x64-gdal-1-9-mapserver-6-2.zip

like image 331
Kliver Max Avatar asked Dec 24 '12 08:12

Kliver Max


People also ask

What is Tomcat native library?

The Apache Tomcat Native Library is an optional component for use with Apache Tomcat that allows Tomcat to use OpenSSL as a replacement for JSSE to support TLS connections.

Does Tomcat include OpenSSL?

OpenSSL is not part of Tomcat, but the OpenSSL library is included in the Tomcat 6 windows binary packages available from apache.org. The library code is integrated into a Tomcat dll, there is no openssl.exe included.

What is Java library path?

java. library. path is a System property, which is used by Java programming language, mostly JVM, to search native libraries, required by a project. Similar to PATH and Classpath environment variable, java.

What is APR Tomcat?

Introduction. Tomcat can use the Apache Portable Runtime to provide superior scalability, performance, and better integration with native server technologies. The Apache Portable Runtime is a highly portable library that is at the heart of Apache HTTP Server 2.


3 Answers

The accepted answer (as of Feb 2016) is just plain wrong.

  • You are never supposed to edit catalina.bat / catalina.sh. Don't ! (The only file in Tomcat's bin/ dir that you are supposed to touch is setenv.bat).

  • The right config variable is CATALINA_OPTS, not JAVA_OPTS.

  • If you are on Windows then you don't want to quote the value for the SET command as the quotes become part the actual value. (unlike on Unix/Linux)

  • It is likely you'll want to retain what is already in java.library.path.

(in the following I'll assume you are on Windows, change accordingly for Linux/Solaris/Mac OSX).

Here's how to do it: Put a file called setenv.bat into the same directory as catalina.bat. The file will not exist, unless you've created it yourself previously. So create the file. It must have the following content for your purpose:

set CATALINA_OPTS=%CATALINA_OPTS% -Djava.library.path=%PATH%;c:\mydlls

On Windows java.library.path will default to %PATH% so an alternative route to all of the above would have been to change your PATH environment variable.

If you do not want to have confusion over exactly from where the JVM will load your native libraries then omit the %PATH%; part from the above. Personally I omit %PATH% for this reason but that is a matter of taste.

like image 89
peterh Avatar answered Oct 19 '22 21:10

peterh


It has to be setup in catalina.bat instead of startup.bat.

set JAVA_OPTS="-Djava.library.path=/usr/tomcat/shared/lib"

can be put after

:noJuliManager
set JAVA_OPTS=%JAVA_OPTS% %LOGGING_MANAGER%
like image 10
coderLMN Avatar answered Oct 19 '22 21:10

coderLMN


According to the comments on catalina.bat, I think the right place is CATALINA_OPTS.

rem   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
rem                   "run" or "debug" command is executed.
rem                   Include here and not in JAVA_OPTS all options, that should
rem                   only be used by Tomcat itself, not by the stop process,
rem                   the version command etc.
rem                   Examples are heap size, GC logging, JMX ports etc.
like image 6
Francesco Avatar answered Oct 19 '22 23:10

Francesco