How to add a native library in Tomcat?

前端 未结 3 1494
闹比i
闹比i 2020-11-28 13:05

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.

相关标签:
3条回答
  • 2020-11-28 13:29

    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%
    
    0 讨论(0)
  • 2020-11-28 13:38

    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.

    0 讨论(0)
  • 2020-11-28 13:43

    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.
    
    0 讨论(0)
提交回复
热议问题