3

背景

我有一个 Matlab 代码库(或现在带有 r2012b 的应用程序),我分发给用户。

这个应用程序将 JNI 与本机库(几个.dll文件)一起使用。在我的本地机器上,这需要 librarypath.txt 或 javalibrarypath.txt (r2012b) 文件中的条目MathworksUndocumented Matlab所述

问题

有没有办法以编程方式将本机库添加到 Matlab java 类路径?

我想编写一个initMyLibrary.m脚本,其中:

  • 用户不必手动修改这些文件。
  • 该代码可用作已编译的 MCR 应用程序。
  • init 不会破坏用户现有的javalibrarypath.txt
  • 假设没有管理员权限(不能修改 Matlab 基础安装)。

有任何想法吗?

4

1 回答 1

0

这可能很混乱,我不是这方面的专家,但在你的initMyLibrary.m中不会有这样的事情:

currentdir = pwd; % or any other directory you know the dll will be in
if ispc
    system(['setx path "%path%;' currentdir '"']); % only works from windows 7 onwards though, for xp or vista youll have to change the registry with reg
elseif isunix
    system(['export PATH=$PATH:' currentdir]); % dont know if this works without admin rights though...
elseif ismac
    % for mac I dont know how to do this without admin rights
else
    error('whatever') % error handling
end

因为我认为如果您的 dll 在系统路径上,这应该没问题,不是吗?不要忘记在应用程序结束时恢复路径。

无论如何,这一切可能有点危险......

于 2012-12-18T14:42:21.510 回答