覆盖MATLAB默认静态javaclasspath的最佳方法 [英] Best way to override MATLAB's default static javaclasspath

查看:372
本文介绍了覆盖MATLAB默认静态javaclasspath的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MATLAB被配置为在搜索用户可修改的动态路径之前搜索其静态Java类路径.不幸的是,静态路径包含许多非常旧的公共库,因此,如果您尝试使用新版本,则可能最终会加载错误的实现并得到错误.

MATLAB is configured to search its static java class path before searching the user-modifiable dynamic path. Unfortunately, the static path contains quite a number of very old public libraries, so if you are trying to use a new version you may end up loading the wrong implementation and get errors.

例如,静态路径包含google-collections.jar的旧副本,该副本早已被Google的番石榴库所取代,并且具有一些相同的类名(例如com.google.common.base.Objects ).结果,如果您调用的Guava方法使用的是此类中的一种较新的方法,则由于会首先找到google-collection jar,最终会收到令人惊讶的NoSuchMethodErrors.

For instance, the static path contains an old copy of the google-collections.jar, which has long been supplanted by Google's guava library and which has some of the same class names (e.g. com.google.common.base.Objects). As a result, if you invoke a Guava method that uses a newer method of one of such a class, you will end up getting surprising NoSuchMethodErrors because the google-collections jar is found first.

从R2012b开始,MATLAB允许您通过将javaclasspath.txt文件放在您的首选项文件夹中来指定要添加到静态路径的其他jar,但这会将jar添加到路径的末尾,并且不允许您覆盖jar内置在MATLAB中.

As of R2012b, MATLAB lets you specify additional jars to add to the static path by putting a javaclasspath.txt file in your preferences folder, but that adds jars to the end of the path, and doesn't let you override jars that are built into MATLAB.

那么解决此问题的最佳方法是什么?

So what is the best way around this?

推荐答案

我收到了Mathworks的官方回复:

I got an official response from Mathworks:

从MATLAB R2013a(也包括R2012b)开始,可以通过在javaclasspath.txt中包含以下行,将类添加到静态Java类路径的前面:

As of MATLAB R2013a (also in R2012b), classes can be added to the front of the static Java class path by including the following line in javaclasspath.txt:

<before>

javaclasspath.txt中此行之后的任何目录都将添加到静态Java类路径的前面.从R2013a开始,这是javaclasspath.txt的未记录使用.

Any directory that is after this line in javaclasspath.txt will be added to the front of the static Java class path. This is an undocumented use of javaclasspath.txt as of R2013a.

但是总体而言,在MATLAB中,无法通过MATLAB 8.0(R2012b)中的javaclasspath.txt获得将类添加到静态Java类路径的前面的功能.

But overall in MATLAB, the ability to add classes to the front of the static Java classpath is not available through javaclasspath.txt in MATLAB 8.0 (R2012b).

MATLAB按以下顺序搜索classpath.txt:

MATLAB searches for classpath.txt in the following order:

  1. 在启动目录中.从MATLAB 8.0(R2012b)开始,如果在该文件中找到该文件,则会显示警告,并且该文件将被忽略.

  1. In the startup directory. As of MATLAB 8.0 (R2012b) a warning will be shown if the file is found there and it will be ignored.

在MATLABPATH环境变量的第一个目录中. (此环境变量在Linux上的bin/matlab shell脚本中使用,通常最终用户不使用.)

In the first directory on the MATLABPATH environment variable. (This environment variable is used in the bin/matlab shell script on Linux and in general is not used by the end-user).

在工具箱/本地目录中.

In the toolbox/local directory.

尽管最终用户通常不使用第2点的MATLABPATH环境变量,但我们可以在变通方法中使用它,以允许在工具箱/本地目录之外读取自定义的classpath.txt.

Although the MATLABPATH environment variable of point 2 is normally not used by end-users we can use it in a workaround to allow reading a custom classpath.txt outside of the toolbox/local directory.

在Windows上:

您将需要创建MATLABPATH环境变量.它的第一个目录应该是带有自定义classpath.txt的目录,并且您还需要添加toolbox \ local目录作为第二个选项.因此,在cmd提示符下,您可以执行以下操作:

You will need to create the MATLABPATH environment variable. The first directory on it should be your directory with the custom classpath.txt AND you will also need to add the toolbox\local directory as second option. So from a cmd prompt you could do:

设置MATLABPATH = c:\ Users \ user \ Documents \ myMATLABClasspath; c:\ Program Files \ MATLAB \ R2012b \ toolbox \ local matlab.exe

set MATLABPATH=c:\Users\user\Documents\myMATLABClasspath;c:\Program Files\MATLAB\R2012b \toolbox\local matlab.exe

这篇关于覆盖MATLAB默认静态javaclasspath的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆