Combine CPLEX and JAVA

2019-05-11 03:28发布

Java - CPLEX

For a seminar at university I need to program a model with java.

Since it is a maximization problem I also need to involve CPLEX methods. Therefore I successfully installed CPLEX on my Mac OS X Version 10.5.8.

To combine CPLEX and Eclipse (I also tried it with Netbeans) I connected my current project with the CPLEX library (Properties>Library>Add Library).

Eclipse recognizes the library because the methods aren't underlinded. Additionally I committed the following argument to my run configurations:

-Djava.library.path=/Users/myname/Applications/IBM/ILOG/CPLEX_Studio126/cplex/bin/x86-64_osx

When I try to run an exemplary code (that is valid) I get the following error:

java.lang.UnsatisfiedLinkError: /Users/myname/Applications/IBM/ILOG/CPLEX_Studio126/cplex/bin/x86-64_osx/libcplex1260.jnilib:  no suitable image found.  Did find:  /Users/myname/Applications/IBM/ILOG/CPLEX_Studio126/cplex/bin/x86-64_osx/libcplex1260.jnilib: unknown required load command 0x80000022Exception in thread "main" java.lang.UnsatisfiedLinkError: ilog.cplex.Cplex.CPXopenCPLEX([I)J
    at ilog.cplex.Cplex.CPXopenCPLEX(Native Method)
    at ilog.cplex.CplexI.init(CplexI.java:6594)
    at ilog.cplex.CplexI.<init>(CplexI.java:629)
    at ilog.cplex.IloCplex.<init>(IloCplex.java:11067)
    at ilog.cplex.IloCplex.<init>(IloCplex.java:11082)
    at Knapsack.buildModel(Knapsack.java:54)
    at Knapsack.main(Knapsack.java:122)

java.library.path must point to the directory containing the CPLEX shared library
try invoking java with java -Djava.library.path=...

could you please be so kind to help me, i don't know any more what to do.

Thank you for an answer

2条回答
Fickle 薄情
2楼-- · 2019-05-11 04:11

I found this question when having the same problem. followed the advice from the internet and found that I was putting the -Djava.library.path argument in the wrong place... You should really double check not only the paths but also if you put your arguments in the correct place and correctly typed. It seems silly but happens :)

Anyway, in my case, I am using NetBeans, I went to:

  • Project Properties
  • Run
  • in the VM Options text field:

    -Djava.library.path=/Applications/IBM/ILOG/CPLEX_Studio126/cplex/bin/x86-64_osx

I hope this will help you

查看更多
SAY GOODBYE
3楼-- · 2019-05-11 04:16
  1. Make sure you closely followed the steps described in 1 for setting up eclipse.

  2. Make sure the environment variable DYLD_LIBRARY_PATH is set in the environment eclipse is running in. See 2. First check if DYLD_LIBRARY_PATH is set. Second try to execute your java program via terminal.

查看更多
登录 后发表回答