Exception in thread "main" java.lang.UnsatisfiedLinkError: no lpsolve55j in java.library.path

6.8k views Asked by At

in .bashrc is written:

PYTHONPATH="${PYTHONPATH}:$Home/local/lib/python2.7/site-packages/"
export PYTHONPATH 

LD_LIBRARY_PATH="$Home/local/lib/"
export LD_LIBRARY_PATH

CLASSPATH="/home/stud/qe09kyvu/local/lib/liblpsolve55j.so"
export CLASSPATH

When i try to run this command:

java -cp .:../lib/lpsolve55j.jar -Djava.library.path=../liblpsolve55j.so Demo

i get the following error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no lpsolve55j in java.library.path

But i don't understand this error, because in .. there is liblpsolve55j.so

3

There are 3 answers

0
vishal.kangralkar On

Setting the java.library path. using Eclipse

1.Select your project in the Package Explorer area and press a right click on it.

2.Select Build Path → Configure Build Path... option.

3.In the appearing window, select the Libraries tab.

4.Then, expand the JRE System library option and select the Native library location.

5.Click on the Edit... button at the right panel.

6.Locate the required library and then click OK.

7.Close the window.

2
Santhosh Gandhe On

To run lpsolver, you need two things.

  1. platform/os specific binary like listed below and you should keep them in the corresponding library path or export corresponding environment specific property

    • libsolve55.dll for windows - either you should copy these files to system32 or set this path to LD_LIBRARY_PATH environment variable
    • libsolve55.so for linux - you should copy these files to /usr/local/lib or set this path to LD_LIBRARY_PATH environment variable
    • libsolve55.dylib for mac - you should copy these files to /usr/local/lib or set this path to LD_LIBRARY_PATH environment variable DYLD_FALLBACK_LIBRARY_PATH
  2. Language specific wrapper for invoking the lp_solver method present in the above binary file. For Java you need liblpsolve55j.jnilib and lpsolve5j.o file. Either the location of these should be added to java.library.path or add them to the above platform-specific environment variable.

In your case, it seems like you are all set in step 2, but you are missing the step 1. For Step 1, instead of environment variable, you can include the path in the java.library.path that you are alreay passing. I gave you an example below.

$ java -cp ./Demo.jar:../lib/lpsolve55j.jar -Djava.library.path=/Users/santhoshgandhe/mac_lpsolver/lp_solve_5.5/lpsolve55/bin/osx64:/Users/santhoshgandhe/mac_lpsolver/lp_solve_5.5_java/lib/mac Demo

0
lfvv On

I manually added the files liblpsolve55.so and liblpsolve55j.so (downloaded in 'https://svn.win.tue.nl/repos/prom/Packages/Alignment/Trunk/dll/') to all my Linux shown paths for java library (obtained with the command 'java -XshowSettings:properties'). After that, my Java program worked (I also added the jar 'lpsolve-5.5.2.0.jar' to the referenced libraries in my Java project)