java.lang.UnsatisfiedLinkError: 没有 GurobiJni/Tomcat

java.lang.UnsatisfiedLinkError: no GurobiJni / Tomcat(java.lang.UnsatisfiedLinkError: 没有 GurobiJni/Tomcat)

本文介绍了java.lang.UnsatisfiedLinkError: 没有 GurobiJni/Tomcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试通过 Java Web 应用程序在 CentOS 中使用 Tomcat 服务器运行 Gurobi.系统变量定义:

We are trying to run Gurobi through a Java web application with Tomcat server in a CentOS. System variables are defined:

declare -x GRB_LICENSE_FILE="/home/suporte/gurobi.lic"
declare -x GUROBI_HOME="/opt/gurobi752/linux64"
declare -x LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${GUROBI_HOME}/lib"
declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$JAVA_HOME/bin:$GUROBI_HOME/bin"

Gurobi 和 Java 工作正常.应用程序在 Tomcat 中也可以正常工作,但是当它调用 Gurobi 时,我们会收到异常:java.lang.UnsatisfiedLinkError: no GurobiJni75 in java.library.path".

Gurobi and Java work fine. Application works fine as well in Tomcat, but when it calls Gurobi, we get the exception: "java.lang.UnsatisfiedLinkError: no GurobiJni75 in java.library.path".

Exception in thread "Thread-14" java.lang.UnsatisfiedLinkError: no GurobiJni75 in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at gurobi.GurobiJni.<clinit>(GurobiJni.java:243)
    at gurobi.GRBEnv.<init>(GRBEnv.java:41)
    at gurobi.GRBEnv.<init>(GRBEnv.java:31)
    at br.com.lapin.otimizacao.model.ModelCorteGurobi.<init>(ModelCorteGurobi.java:43)

有解决问题的办法吗?

这里是脚本输出...

java.vendor:Oracle Corporation sun.java.launcher:SUN_STANDARD catalina.base:/opt/tomcat sun.management.compiler:HotSpot 64 位分层编译器 catalina.useNaming:trueos.name:Linux sun.boot.class.path:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/resources.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/rt.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/jsse.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/jce.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/charsets.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/jfr.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/classes java.util.logging.config.file:/opt/tomcat/conf/logging.properties java.vm.specification.vendor:甲骨文公司 java.runtime.version:1.8.0_161-b14 用户名:tomcat tomcat.util.scan.StandardJarScanFilter.jarsToScan:log4j-web*.jar、log4j-taglib*.jar、log4javascript*.jar、slf4j-taglib*.jar shared.loader:tomcat.util.buf.StringCache.byte.enabled:true user.language:en java.naming.factory.initial:org.apache.naming.java.javaURLContextFactory sun.boot.library.path:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/amd64 jdk.tls.ephemeralDHKeySize:2048 java.version:1.8.0_161 java.util.logging.manager:org.apache.juli.ClassLoaderLogManager 用户.timezone:等/UTC sun.arch.data.model:64 java.util.concurrent.ForkJoinPool.common.threadFactory:org.apache.catalina.startup.SafeForkJoinWorkerThreadFactory java.endorsed.dirs:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/endorsed sun.cpu.isalist:sun.jnu.encoding:UTF-8 file.encoding.pkg:sun.io 包.访问:sun.、org.apache.catalina.、org.apache.coyote.、org.apache.jasper.、org.apache.tomcat.file.separator:/java.specification.name:Java 平台 API 规范 java.class.version:52.0 user.country:美国 java.home:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jrejava.vm.info:混合模式 os.version:3.10.0-693.17.1.el7.x86_64 path.separator::java.vm.version:25.161-b14 java.protocol.handler.pkgs:org.apache.catalina.webresources java.awt.printerjob:sun.print.PSPrinterJob sun.io.unicode.encoding:UnicodeLittle awt.toolkit:sun.awt.X11.XToolkit package.definition:sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.naming.,org.apache.tomcat.java.naming.factory.url.pkgs : org.apache.naming java.security.egd : 文件:/dev/./urandom user.home :/opt/tomcat java.specification.vendor : Oracle Corporation tomcat.util.scan.StandardJarScanFilter.jarsToSkip : bootstrap.jar,commons-daemon.jar,tomcat-juli.jar,annotations-api.jar,el-api.jar,jsp-api.jar,servlet-api.jar,websocket-api.jar,jaspic-api.jar,catalina.jar,catalina-ant.jar,catalina-ha.jar,catalina-storeconfig.jar,catalina-tribes.jar,jasper.jar,jasper-el.jar,ecj-.jar、tomcat-api.jar、tomcat-util.jar、tomcat-util-scan.jar、tomcat-coyote.jar、tomcat-dbcp.jar、tomcat-jni.jar、tomcat-websocket.jar、tomcat-i18n-en.jar、tomcat-i18n-es.jar、tomcat-i18n-fr.jar、tomcat-i18n-ja.jar、tomcat-juli-adapters.jar、catalina-jmx-remote.jar、catalina-ws.jar,tomcat-jdbc.jar,tools.jar,commons-beanutils.jar,commons-codec*.jar,commons-collections*.jar,commons-dbcp*.jar,commons-digester*.jar,commons-fileupload*.jar,commons-httpclient*.jar,commons-io*.jar,commons-lang*.jar,commons-logging*.jar,commons-math*.jar,commons-pool*.jar,jstl.jar,taglibs-standard-spec-.jar,geronimo-spec-jaxrpc.jar,wsdl4j*.jar,ant.jar,ant-junit*.jar,aspectj*.jar,jmx.jar,h2*.jar,hibernate*.jar,httpclient*.jar,jmx-tools.jar,jta*.jar,log4j*.jar,mail*.jar,slf4j*.jar,xercesImpl.jar,xmlParserAPIs.jar,xml-apis.jar,junit.jar,junit-.jar,hamcrest-.jar,easymock-.jar,cglib-.jar,objenesis-.jar,ant-launcher.jar,cobertura-.jar,asm-.jar,dom4j-.jar,icu4j-.jar,jaxen-.jar,jdom-.jar,jetty-.jar,oro-.jar,servlet-api-.jar,tagsoup-.jar,xmlParserAPIs-.jar,xom-.jar java.library.path :/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib java.vendor.url :http://java.oracle.com/ ld.library.path :/opt/gurobi752/linux64/lib/java.vm.vendor : Oracle Corporation common.loader : "${catalina.base}/lib","${catalina.base}/lib/.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar","/usr/local/gurobi605/linux64" java.runtime.name : OpenJDK 运行时环境 sun.java.command : org.apache.catalina.startup.Bootstrap start java.class.path :/opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jarjava.vm.specification.name:Java 虚拟机规范 java.vm.specification.version:1.8 catalina.home:/opt/tomcat sun.cpu.endian:小 sun.os.patch.level:未知 java.awt.headless:真 java.io.tmpdir:/opt/tomcat/temp java.vendor.url.bug:http://bugreport.sun.com/bugreport/ server.loader : "/opt/gurobi752/linux64/lib/gurobi.jar" os.arch : amd64 java.awt.graphicsenv: sun.awt.X11GraphicsEnvironment java.ext.dirs :/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/ext:/usr/java/packages/lib/ext user.dir :/line.separator :java.vm.name : OpenJDK 64-Bit Server VM ignore.endorsed.dirs : file.encoding : UTF-8 java.specification.version : 1.8

java.vendor : Oracle Corporation sun.java.launcher : SUN_STANDARD catalina.base : /opt/tomcat sun.management.compiler : HotSpot 64-Bit Tiered Compilers catalina.useNaming : trueos.name : Linux sun.boot.class.path : /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/resources.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/rt.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/jsse.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/jce.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/charsets.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/jfr.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/classes java.util.logging.config.file : /opt/tomcat/conf/logging.properties java.vm.specification.vendor : Oracle Corporation java.runtime.version : 1.8.0_161-b14 user.name : tomcat tomcat.util.scan.StandardJarScanFilter.jarsToScan : log4j-web*.jar,log4j-taglib*.jar,log4javascript*.jar,slf4j-taglib*.jar shared.loader : tomcat.util.buf.StringCache.byte.enabled : true user.language : en java.naming.factory.initial : org.apache.naming.java.javaURLContextFactory sun.boot.library.path : /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/amd64 jdk.tls.ephemeralDHKeySize : 2048 java.version : 1.8.0_161 java.util.logging.manager : org.apache.juli.ClassLoaderLogManager user.timezone : Etc/UTC sun.arch.data.model : 64 java.util.concurrent.ForkJoinPool.common.threadFactory : org.apache.catalina.startup.SafeForkJoinWorkerThreadFactory java.endorsed.dirs : /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/endorsed sun.cpu.isalist : sun.jnu.encoding : UTF-8 file.encoding.pkg :sun.io package.access : sun.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.tomcat. file.separator : /java.specification.name : Java Platform API Specification java.class.version : 52.0 user.country : US java.home : /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jrejava.vm.info : mixed mode os.version : 3.10.0-693.17.1.el7.x86_64 path.separator : : java.vm.version : 25.161-b14 java.protocol.handler.pkgs : org.apache.catalina.webresources java.awt.printerjob : sun.print.PSPrinterJob sun.io.unicode.encoding : UnicodeLittle awt.toolkit : sun.awt.X11.XToolkit package.definition : sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.naming.,org.apache.tomcat. java.naming.factory.url.pkgs : org.apache.naming java.security.egd : file:/dev/./urandom user.home : /opt/tomcat java.specification.vendor : Oracle Corporation tomcat.util.scan.StandardJarScanFilter.jarsToSkip : bootstrap.jar,commons-daemon.jar,tomcat-juli.jar,annotations-api.jar,el-api.jar,jsp-api.jar,servlet-api.jar,websocket-api.jar,jaspic-api.jar,catalina.jar,catalina-ant.jar,catalina-ha.jar,catalina-storeconfig.jar,catalina-tribes.jar,jasper.jar,jasper-el.jar,ecj-.jar,tomcat-api.jar,tomcat-util.jar,tomcat-util-scan.jar,tomcat-coyote.jar,tomcat-dbcp.jar,tomcat-jni.jar,tomcat-websocket.jar,tomcat-i18n-en.jar,tomcat-i18n-es.jar,tomcat-i18n-fr.jar,tomcat-i18n-ja.jar,tomcat-juli-adapters.jar,catalina-jmx-remote.jar,catalina-ws.jar,tomcat-jdbc.jar,tools.jar,commons-beanutils.jar,commons-codec*.jar,commons-collections*.jar,commons-dbcp*.jar,commons-digester*.jar,commons-fileupload*.jar,commons-httpclient*.jar,commons-io*.jar,commons-lang*.jar,commons-logging*.jar,commons-math*.jar,commons-pool*.jar,jstl.jar,taglibs-standard-spec-.jar,geronimo-spec-jaxrpc.jar,wsdl4j*.jar,ant.jar,ant-junit*.jar,aspectj*.jar,jmx.jar,h2*.jar,hibernate*.jar,httpclient*.jar,jmx-tools.jar,jta*.jar,log4j*.jar,mail*.jar,slf4j*.jar,xercesImpl.jar,xmlParserAPIs.jar,xml-apis.jar,junit.jar,junit-.jar,hamcrest-.jar,easymock-.jar,cglib-.jar,objenesis-.jar,ant-launcher.jar,cobertura-.jar,asm-.jar,dom4j-.jar,icu4j-.jar,jaxen-.jar,jdom-.jar,jetty-.jar,oro-.jar,servlet-api-.jar,tagsoup-.jar,xmlParserAPIs-.jar,xom-.jar java.library.path : /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib java.vendor.url :http://java.oracle.com/ ld.library.path : /opt/gurobi752/linux64/lib/ java.vm.vendor : Oracle Corporation common.loader : "${catalina.base}/lib","${catalina.base}/lib/.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar","/usr/local/gurobi605/linux64" java.runtime.name : OpenJDK Runtime Environment sun.java.command : org.apache.catalina.startup.Bootstrap start java.class.path : /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jarjava.vm.specification.name : Java Virtual Machine Specification java.vm.specification.version : 1.8 catalina.home : /opt/tomcat sun.cpu.endian : little sun.os.patch.level : unknown java.awt.headless : true java.io.tmpdir : /opt/tomcat/temp java.vendor.url.bug : http://bugreport.sun.com/bugreport/ server.loader : "/opt/gurobi752/linux64/lib/gurobi.jar" os.arch : amd64 java.awt.graphicsenv : sun.awt.X11GraphicsEnvironment java.ext.dirs : /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/ext:/usr/java/packages/lib/ext user.dir : / line.separator :java.vm.name : OpenJDK 64-Bit Server VM ignore.endorsed.dirs : file.encoding : UTF-8 java.specification.version : 1.8

推荐答案

有解决问题的办法吗?

Any idea to solve the problem?

你可以设置LD_LIBRARY_PATH指向Gurobi存放.so文件的目录,也可以设置.jar文件存放的目录.

You can set LD_LIBRARY_PATH to point to the directory of Gurobi where the .so files are stored, and also the directory where the .jar files are stored.

您还可以通过复制或链接来使 Gurobi jar 文件从 Tomcat 中访问.

You can also make Gurobi jar file accessible from Tomcat by copying or linking it.

ln -sv $GUROBI_HOME/lib/gurobi.jar $TOMCAT_HOME/lib/

编辑 1

试试

declare -x LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${GUROBI_HOME}/lib"

而不是

declare -x LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${GUROBI_HOME}/lib"

使用 有错误,您没有复制/粘贴官方文档.

There is a mistake by using , and you didn't copy/paste the official doc.

为了进一步调试,创建一个包含此内容的 JSP,它显示所有系统属性,我们将看到 java.library.path.奇怪的是以前没有人发过这个.

For further debugging, create a JSP with this content, it displays all System properties and we'll see java.library.path. It's weird nobody ever posted this before.

<%@ page import="java.util.Properties" %>
<%@ page import="java.util.Set" %>

<%
Properties p = System.getProperties();

Set<String> keys = p.stringPropertyNames();
for (String key : keys)
  out.println(key + " : " + p.getProperty(key));

%>

编辑 2

从您的调试 JSP 中,我们看到 ld.library.path 正确指向您的 GUROBI lib 目录.我们可以尝试为 java.library.path 添加系统属性.在您的 Tomcat 安装中,使用以下内容编辑或创建 bin/setenv.sh 文件:

From your debug JSP we see that ld.library.path is correctly pointing to your GUROBI lib directory. We can try adding a System Property for java.library.path. In your Tomcat installation, edit or create bin/setenv.sh file with this content :

CATALINA_OPTS="-Djava.library.path=/opt/gurobi752/linux64/lib/"

可以阅读这里对此建议的解释.

An explanation to this suggestion can be read here.

顺便说一句,我不知道您将 declare -x 放在哪里,但是将它们存储在 bin/setenv.sh

btw I don't know where you put your declare -x , but it would be legitimate to store them in bin/setenv.sh

这篇关于java.lang.UnsatisfiedLinkError: 没有 GurobiJni/Tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:java.lang.UnsatisfiedLinkError: 没有 GurobiJni/Tomcat