In Matlab R2018a under Windows 8, after executing a jar file throwing exceptions AddressException, MessagingException (ref. code ref.1) from the system() MATLAB Command, the jar file handle got locked.
1:java.nio.file.FileSystemException: HelloWorld.jar: The process cannot access the file because it is being used by another process.
Because the system shell (Command Prompt) call: [status,result]=system(command) or ! has finished its execution, the proper handle is lost (where?) and it is not possible to close it. Note that the status and result parameters are only the error message and a return int, without any handle reference.
When checking the Associated Handle HelloWorld with Windows resmon.exe, we got:
Matlab.exe | <pid> | File | <path\to\java\file.jar>
When triyng to delete HelloWorld.jar, we got:
File in Use. The action can't be completed because the file is open in MATLAB R2018a.
The following approaches do not work:
- Closing File Handles,
fclose('all'), since nofopencommand is (directly?) involved (ref.2, ref.3), - Java Garbage Collection
java.lang.System.gc(),java.lang.Runtime.getRuntime().gc,clear java,clear allsince no Java Object has been created (yet), - Clearing Java Path
javarmpath('HelloWorld.jar'), since no Java Path has been added (yet).
How should I release that handle, without closing MATLAB?.