Manon
Manon

Reputation: 73

Error in java.library.path when calling a Java function that uses Cplex, from Matlab

I would like to call a Java function that uses Cplex, from Matlab. At the moment, I am stuck. Below is a list of things I tried, but I am out of ideas. Before I get there, let me list the versions:

  1. Matlab version 8.3.0.532 (R2014a)
  2. Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
  3. Eclipse with jre7 and jdk1.7.0_79

I created a package "milp.jar" and try to call the following function from Matlab:

milp.MTsolver.Plan() 

In a basic version of my milp.jar, without any Cplex functionality, this goes without problems. Just as soon as I use a Cplex function in my Java class, I get in trouble. I tried the following:

To be able to use Cplex, I added the path to the javaclasspath.txt file in the Matlab folder

prefdir 

The command

javaclasspath 

in Matlab console indeed shows that this path is added to the Static Java Path. But then, when calling my cplex dependent function milp.MTsolver.Plan(), I get the following error:

Java exception occurred:
java.lang.UnsatisfiedLinkError: no cplex1262 in java.library.path
java.library.path must point to the directory containing the CPLEX shared library
try invoking java with java -Djava.library.path=...

Following this post, I should first load the library:

java.lang.System.load('C:\Program Files\IBM\ILOG\CPLEX_Studio1262\cplex\lib\cplex.jar');

But this gives the following error:

Java exception occurred:
java.lang.UnsatisfiedLinkError: C:\Program Files\IBM\ILOG\CPLEX_Studio1262\cplex\lib\cplex.jar: %1 is not a valid Win32 application

At his point, I tried another approach. I just copied the cplex.jar into the Matlab root folder. No success. Nor any succes when just copying the cplex.jar in the project folder in Matlab.

Then, I tried to find a cplex1262.jar, but I only found a cplex1262.dll. So I added this path to the Static Java Path. This gives the following error:

Java exception occurred:
java.lang.UnsatisfiedLinkError: ilog.cplex.Cplex.CPXopenCPLEX([I)J

The same error occurs when I run the following in the Matlab console:

java.lang.System.load('C:\Program Files\IBM\ILOG\CPLEX_Studio1262\opl\oplide\plugins\ilog.odms.ide.opllang.win32.win32.x86_64_12.6.2.0\cplex1262.dll');

A last thing I could try comes from an answer in this post. Here, he sets

-Djava.library.path=... 

in the VM Options field, but in Netbeans. I could try to do something similar in Matlab, but I have not figured out yet how. Last, I just added the directories containing cplex.jar and cplex1262.dll to the PATH environment variable. No luck there either.

Another important note might be that I have no problem running my code in Eclipse, including Cplex functionality! It might also be worth mentioning that, in between changes, I restarted Matlab to be sure that all changes in path settings took effect.

I hope to have stated my problem clearly enough. Any suggestions on how to proceed are very welcome!

Upvotes: 1

Views: 807

Answers (1)

Manon
Manon

Reputation: 73

I was able to find a quick and dirty solution, which is ok for now. First I tried to add the path to the directory containing cplex1262.dll to the 'java.library.path' as follows:

java.lang.System.setProperty('java.library.path', [path to dir])

But that did not work for me. In a quick and dirty manner, I looked up what paths were already included in this property, with the following command.

>> java.lang.System.getProperty('java.library.path')

ans =

C:\Program Files\MATLAB\R2014a\bin\win64;C:\Program Files\MATLAB\R2014a\sys\jxbrowser\win64\lib

And just copy/pasted the cplex1262.dll in the \lib directory.

That worked.

Upvotes: 1

Related Questions