在Windows 8下的Matlab R2018a中,在执行jar
文件后,从AddressException
MATLAB抛出异常MessagingException
,system()
(参考代码ref.1)命令,jar
文件句柄被锁定。
1:java.nio.file.FileSystemException: HelloWorld.jar: The process cannot access the file because it is being used by another process.
由于系统外壳程序(命令提示符)调用:[status,result]=system(command)
或!
已完成执行,因此丢失了正确的句柄(在何处?)并且无法将其关闭。请注意,status
和result
参数只是错误消息和返回int,没有任何句柄引用。
在Windows HelloWorld
上检查关联句柄resmon.exe
时,我们得到:
Matlab.exe | <pid> | File | <path\to\java\file.jar>
当您尝试删除HelloWorld.jar
时,我们得到了:
File in Use. The action can't be completed because the file is open in MATLAB R2018a.
以下方法无效:
fclose('all')
,因为没有fopen
命令(直接吗?)涉及(ref.2,ref.3)java.lang.System.gc()
,java.lang.Runtime.getRuntime().gc
,clear java
,clear all
javarmpath('HelloWorld.jar')
,因为尚未添加Java路径。如何在不关闭MATLAB的情况下释放该句柄?