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

7 次查看(过去 30 天)
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?

采纳的回答

MathWorks Support Team
MathWorks Support Team 2024-4-9,0:00
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Java Package Integration 的更多信息

标签

尚未输入任何标签。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by