Azzera filtri
Azzera filtri

Can I use custom macros to define the path to my native methods library?

1 visualizzazione (ultimi 30 giorni)
My MATLAB code uses a Java class that dynamically loads native methods using the Java method java.lang.System.loadLibrary("LibFile"). I am using a "javalibrarypath.txt" file to add the location of the native method library to the Java Library Path, as outlined in this documentation:
https://www.mathworks.com/help/matlab/matlab_external/locate-native-method-libraries.html
The path to the native method library changes often, depending on which version I am using. It is tedious to change the hard-coded path in the "javalibrarypath.txt" file each time. Is there a way to encode the path with custom macros, similar to the $matlabroot, $arch, and $jre_home documented macros?

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 9 Apr 2024
MATLAB only supports the documented macros $jre_home, $matlabroot and $arch in javalibrarypath.txt. These macros are recognized in the source code: $jre_home matches the location sys/java/jre by default, $matlab_root is the same as matlabroot, and $arch is win64 on Windows etc. It is not possible to use custom macros. However, there are two possible ways to make it easier to switch between different library paths.
1. Instead of using the "javalibrarypath.txt", the customer can use LD_LIBRARY_PATH to manage the library versions. For example:
setenv LD_LIBRARY_PATH/my/native/library/folder/v1
matlab -r myJavaApp
setenv LD_LIBRARY_PATH/my/native/library/folder/v2
matlab -r myJavaApp
2. Create one "javalibrarypath.txt" for each version, and start MATLAB from the corresponding folder. For example, create a "javalibrarypath.txt" file in folder v1 and v2 for the desired libraries and do the following:
cd /my/native/library/folder/v1
matlab -r myJavaApp
cd /my/native/library/folder/v2
matlab -r myJavaApp

Più risposte (0)

Categorie

Scopri di più su Java Package Integration in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by