java.library.path, classpath Netbeans 8.0.2
Asked Answered
A

3

14

I have just installed the Matlab Runtime on:

Distributor ID: Ubuntu
Description:    Ubuntu 15.04
Release:    15.04
Codename:   vivid

You can find the Matlab runtime here in my case in installed R2015b (9.0)* (MATLAB Runtime 9.0, for R2015b, is intended to work with MATLAB 8.6, which is also R2015b).

The Matlab libraries get installed to: /usr/local/MATLAB

I am using Netbeans 8.0.2

java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode) 

The error I get off my program is as follows:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to find the required library libmwmclmcrrt.so.9.0 on java.library.path.
This library is typically installed along with MATLAB or the MCR. Its absence may indicate an issue with that installation or the current path configuration.
The MCR version that this component is trying to use is: 9.0.

On the install of Matlab it does say:

On the target computer, append the following to your LD_LIBRARY_PATH environment variable:  /usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64:

I have added this line to Project > Properties > VM Options:

-Djava.library.path="/usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64:"

And I have added the same folders to Project > Properties > Libraries using the: Add JAR/Folder button.

I have put the following line of code into my program:

System.out.println(System.getProperty("java.library.path"));

To which I get output correctly as:

/usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64:

However, it continues to fail to run with the same error.

I installed IntelliJ IDEA Community edition and with no mods at all and the code just runs without any issues. I really wish to keep with Netbeans and would like to understand the issue. Any ideas?

IntelliJ has the following loaded:

/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java 
-Didea.launcher.port=7532 
-Didea.launcher.bin.path=/home/code/idea-IC-143.1821.5/bin 
-Dfile.encoding=UTF-8 
-classpath /usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/charsets.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/cldrdata.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/dnsns.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/icedtea-sound.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/java-atk-wrapper.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/localedata.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/nashorn.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/sunec.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/sunjce_provider.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/sunpkcs11.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/zipfs.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/jce.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/jsse.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/management-agent.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/resources.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/rt.jar

:/home/code/NetBeansProjects/CO2model/out/production/TestModelABC
:/home/code/NetBeansProjects/CO2model/TestModelABC/dist/lib/co2model.jar
:/home/code/NetBeansProjects/CO2model/TestModelABC/dist/lib/javabuilder.jar
:/home/code/NetBeansProjects/CO2model/for_redistribution_files_only/co2model.jar
:/home/code/idea-IC-143.1821.5/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain test.Startup
.
:
:/usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64
:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64
:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64
:
:/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni
:/lib/x86_64-linux-gnu
:/usr/lib/x86_64-linux-gnu
:/usr/lib/jni
:/lib
:/usr/lib
Annunciator answered 12/2, 2016 at 0:6 Comment(4)
A guess... maybe your Netbeans doesn't have the LD_LIBRARY_PATH env variable? Try closing netbeans, then run export LD_LIBRARY_PATH=/usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64: ; netbeans & to restart it.Amiraamis
I believe that setting java.library.path is not enough, it works when loading immediate native libraries, but fails when those libraries are referencing other native libraries of their own. You should also set the OS-specific variable for finding shared libraries (PATH on Windows, LD_LIBRARY_PATH on Linux, and DYLD_LIBRARY_PATH on Mac).Toponym
One more thing to note, the docs recommend using the same Java version that MATLAB is using (1.7 not 1.8), both runtime and JDK. You can check by running the command version -java inside MATLAB.Toponym
We also use the MCR, but on Windows systems. As a default, the system property java.library.path maps to the PATH environment variable. On Linux systems, it is LD_LIBRARY_PATH, I guess. This path variable should contain the directoy to the runtime libraries. On Windows this is <mcr-dir>\runtime\win64. The classpath does not need to have this directory. It only needs to have the appropriate JAR file (we use the javabuilder.jar).Impurity
P
1

java.library.path is the path that java uses to find native libraries.. An error would be caused if

  • There is no file called libmwmclmcrrt.so in the path
  • The permissions of the file libmwmclmcrrt.so is not correct

So my advice would be to run a search with name libmwmclmcrrt.so to know whether the file is in the system or not.. If found you could manually copy-paste it to this path

/usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64

If already present in that path maybe you could check the file permissions..

In most of the cases the error is caused because the library isn't found..

Pyknic answered 19/2, 2016 at 8:15 Comment(0)
C
0

to set java.library.path in netbeans. Select project, right click on Properties. Select Run option, Change VM options to add native library -Djava.library.path="absolute\path\to\your\library\files".

java.library.path option

after this, you need to load the library through `System.load("absolute\path\to\your\library\files");' in static block.

like this

static {
  try {
    System.load("absolute\path\to\your\library\files");
  } catch (UnsatisfiedLinkError e) {
    System.err.println("Native code library failed to load.\n" + e);
    System.exit(1);
  }
}

also modify the LD_LIBRARY_PATH environment variable to include the path where the matlab library is located.

export LD_LIBRARY_PATH=/path/to/your/library:$LD_LIBRARY_PATH
Chevalier answered 23/2, 2016 at 8:58 Comment(0)
A
0

I think we have a better explanation here.

In short:

  • Some system property is only read once when the JVM is started up, thus changing it after start-up will not make JVM load it again, so System.setProperty() will not work.
  • In particular, java.library.path is read-only.

So, the only way to set it, is to set %PATH% in Windows, or $LD_LIBRARY_PATH in Linux-like systems.

To set it system-wide in Linux, edit /etc/environment. If you want to set it only user-wide, check this very practical article.

LD_LIBRARY_PATH="/some/preset/path:/your/path/to/add"

Plus: in case that you don't know it, a locate libmwmclmcrrt.so.9.0 is always very helpful in this situation, specially when you may have various version of a file in different location with identical name. And /your/path/to/add is a directory.

Antechamber answered 15/11, 2016 at 16:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.