gpt4 book ai didi

java - 重新编译时,Matlab 看不到 java 类的变化

转载 作者:行者123 更新时间:2023-11-30 03:44:01 25 4
gpt4 key购买 nike

我使用 Matlab 并尝试从中启动 java 类。所以我将java类的路径添加到Matlab中的classpath.txt中。然后我创建了一个 java 类 HelloWorld 的对象,它完美地工作了:

o = HelloWorld;
javaMethod('main', o);

但是,当我更改 Helloworld 中的代码时,Matlab 没有看到这一点:我需要重新启动 Matlab 才能使用 Helloworld 中更改的代码。

有没有办法强制 Matlab 在不重新启动的情况下查看 Helloworld 中的更改?

最佳答案

我猜你尝试过Matlab clear classes没有成功

如果我摘自 Yair Altman“MATLAB-Java 编程的未记录 secret ”:

如果您没有更改 java 类签名,您也许可以逃脱它:

Java classes are not reloaded automatically by Matlab, when recompiled outside Matlab . to reload a modified Java class, we need to restart the JVM by restarting Matlab . For classes placed on the dynamic classpath, you can try Matlab’s clear(‘java’) command, while remembering its side effect of clearing all globals . However, this does not always work (e .g ., if the class signature has changed).

显然,如果您觉得自己是一名专业的 Java 程序员,那么有一些潜在的解决方法:

Expert Java programmers can try to use Paul Milenkovic’s suggestion for a proxy classloader, as an alternative to restarting Matlab or clearing Java . as Dan Spielman explains, “the rough idea is that you create a classloader for your class, and then access it through the classloader . after you recompile, you kill the classloader and then create a new instance of it, which then reads the recompiled class” .

但底线是:

In practice, I suggest restarting Matlab after Java classes are recompiled, even when this is not strictly necessary . It may save a lot of frustrating debugging and chasing down errors that only happen because Matlabkeeps an old class in memory.

关于java - 重新编译时,Matlab 看不到 java 类的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26200749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com