我正在尝试将GLPK用于我的Java项目。我按照此处https://wiki.nps.edu/pages/viewpage.action?pageId=113606659的链接安装和配置Java的GLPK。在Java项目中,我使用了
compile 'org.gnu.glpk:glpk-java:1.12.0'
包括glpk java项目。另外,我将jar glpk-java-1.12.0.jar复制到了项目lib文件夹中,该文件由gradle包含为
flatDir {
dirs 'lib'
}
下面是我的测试代码
public class ILPTest {
@SuppressWarnings({ "rawtypes", "unchecked"})
public static void main(String[] args) {
testGLPK();
}
private static void testGLPK() {
System.out.println(GLPK.glp_version());
}
}
但是,当我运行它时,出现以下错误
The dynamic link library for GLPK for Java could not be loaded.
Consider using
java -Djava.library.path=
The current value of system property java.library.path is:
/Users/heya/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
java.vendor: Oracle Corporation
java.version: 1.8.0_172
java.vm.name: Java HotSpot(TM) 64-Bit Server VM
java.vm.version: 25.172-b11
java.runtime.version: 1.8.0_172-b11
data model: 64 bit
Exception in thread "main" java.lang.UnsatisfiedLinkError: no glpk_java 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 org.gnu.glpk.GLPKJNI.<clinit>(GLPKJNI.java:29)
at org.gnu.glpk.GLPK.glp_version(GLPK.java:2296)
at com.ILPTest.testGLPK(ILPTest.java:46)
at com.ILPTest.main(ILPTest.java:36)
我在这里想念什么?请帮忙。
答案 0 :(得分:0)
在IntelliJ中配置-Djava.library.path=/usr/local/lib/jni
之后,它可以正常工作。