How to clean the dynamic java path properly?

We are facing an issue when removing a directory from MATLAB path after adding jar-file paths to dynamic javapath:
* The task is to add several folders to MATLAB Path. These folders also contain .jar-files
* Regarding java, we add the full directory paths of .jar files to the dynamic java path
* Later these paths shall be removed again
* In addition, we remove the directory containing these files from MATLAB path again
* We want to delete the directory containing the jar files via rmdir()
However, the last step of rmdir() is not possible as the jar files are not removed properly from the path.
Is there any way to achieve the removal of jar files from path so the directory can be removed via rmdir?

 採用された回答

MathWorks Support Team
MathWorks Support Team 2022 年 5 月 5 日

0 投票

In order to remove jar files properly, java garbage collection must be used:
cellDynPath = javaclasspath('-dynamic');
javarmpath(cellDynPath{:});
java.lang.System.gc();
cellfun(@(x)rmpath(x), cellDynPath)
java.lang.System.gc(); % using gc twice is required

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFile Operations についてさらに検索

製品

タグ

タグが未入力です。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by