java.lang.UnsatisfiedLinkError:no GurobiJni / Tomcat

时间:2018-03-22 17:40:07

标签: java tomcat centos unsatisfiedlinkerror gurobi

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

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:java.library.path中没有GurobiJni75"。

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:Oracle Corporation java.runtime.version:1.8.0_161-b 14 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:混合模式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,卡塔利娜-的ant.jar,卡塔利娜-ha.jar,卡塔利娜-storeconfig.jar,卡塔利娜-tribes.jar,jasper.jar,碧玉-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的巨力-adapters.jar,卡塔利娜-JMX-remote.jar,卡塔利娜-ws.jar ,Tomcat的了jdbc.jar,tools.jar中,公地的BeanUtils 的.jar,公地编解码器的* .jar,公共的集合的* .jar,公地DBCP的* .jar,公地消化器的* .jar,公共-fileupload的* .jar,公地的HttpClient的* .jar,公共-IO的* .jar,公地郎的* .jar,共享记录的* .jar,公地数学* .J AR,公共池的* .jar,的jstl.jar,标记库规格的规格 - 的.jar,Geronimo的SPEC-JAXRPC 的.jar,WSDL4J的* .jar,的ant.jar,蚂蚁的junit *的.jar,AspectJ中的* .jar,jmx.jar,H2的* .jar,冬眠的* .jar,HttpClient的的* .jar,JMX-tools.jar中,JTA的* .jar的是,log4j的* .jar,邮件的* .jar,SLF4J *的.jar,xercesImpl.jar,xmlParserAPIs.jar,XML-apis.jar,的junit.jar,junit- 的.jar,hamcrest - 的.jar,easymock- 的.jar,CGLIB - 的.jar,objenesis- 的.jar,蚂蚁launcher.jar,的Cobertura - 的.jar,asm- 的.jar,DOM4J - 的.jar,icu4j- 的.jar,Jaxen的 - 的.jar,jdom- 的.jar,码头 - 的.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:&#34; $ {catalina。基} / lib中&#34;&#34; $ {catalina.base} / LIB / 的.jar&#34;&#34; $ {的catalina.home} / lib中&#34;&#34 ; $ {的catalina.home} / lib中/ *罐子&#34;&#34;在/ usr /本地/ gurobi605 / LINUX64&#34; 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: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:&#34; /opt/gurobi752/linux64/lib/gurobi.jar& #34; 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位服务器VM ignore.endorsed.dirs:file.encoding:UTF-8 java .specification.version:1.8

1 个答案:

答案 0 :(得分:1)

  

有什么想法解决这个问题吗?

您可以将LD_LIBRARY_PATH设置为指向存储.so文件的Gurobi目录,以及存储.jar文件的目录。

您还可以通过复制或链接从Tomcat访问Gurobi jar文件。

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"

使用\时出错,并且您没有复制/粘贴官方文档。

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

<%@ 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文件:

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

可以阅读here对此建议的解释。

btw我不知道你把declare -x放在哪里,但将它们存放在bin / setenv.sh中是合理的