You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Michael, I made a fork of this project at https://github.com/mscarlett/opencv/tree/windows-patch (which I can submit as a pull request) and was able to use the library successfully on Windows. However if the OpenCV.loadLocally() method is called, the TemporaryDirectory.delete() method throws an AccessDeniedError when the JVM is terminating due to not having permission to delete the DLL file in the temporary directory. As a result the binaries still reside in the temporary directory after the program terminates. This issue does not occur in Linux so it appears Windows specific.
The error is likely due to the JVM locking this file once the DLL file is loaded, but I was unable to find documentation regarding why it happens.
Here is the full stack trace in case it helps:
Exception in thread "Thread-1" java.lang.RuntimeException: java.nio.file.AccessDeniedException: C:\Users\Michael\AppData\Local\Temp\5989570558901519688\nu\pattern\opencv\windows\x86_64\libopencv_java249.dll
at nu.pattern.OpenCV$TemporaryDirectory.delete(OpenCV.java:146)
at nu.pattern.OpenCV$TemporaryDirectory$1.run(OpenCV.java:117)
Caused by: java.nio.file.AccessDeniedException: C:\Users\Michael\AppData\Local\Temp\5989570558901519688\nu\pattern\opencv\windows\x86_64\libopencv_java249.dll
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.implDelete(Unknown Source)
at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(Unknown Source)
at java.nio.file.Files.deleteIfExists(Unknown Source)
at nu.pattern.OpenCV$TemporaryDirectory$2.visitFile(OpenCV.java:141)
at nu.pattern.OpenCV$TemporaryDirectory$2.visitFile(OpenCV.java:1)
at java.nio.file.Files.walkFileTree(Unknown Source)
at java.nio.file.Files.walkFileTree(Unknown Source)
at nu.pattern.OpenCV$TemporaryDirectory.delete(OpenCV.java:130)
The text was updated successfully, but these errors were encountered:
mscarlett
changed the title
Unable to delete binaries in Windows due to AccessDeniedException
Unable to delete temporary DLL file in Windows due to AccessDeniedException
Jul 14, 2015
According to http://stackoverflow.com/questions/453359/how-to-unload-dll-from-java-jvm it is necessary to load the DLL with a custom class loader so that it can be garbage collected to unload the DLL file on Windows. Otherwise this might require spawning a process that deletes the DLL file after the JVM terminates. Apparently Windows does not make it possible to delete DLLs that are still being used.
Hi Michael, I made a fork of this project at https://github.com/mscarlett/opencv/tree/windows-patch (which I can submit as a pull request) and was able to use the library successfully on Windows. However if the OpenCV.loadLocally() method is called, the TemporaryDirectory.delete() method throws an AccessDeniedError when the JVM is terminating due to not having permission to delete the DLL file in the temporary directory. As a result the binaries still reside in the temporary directory after the program terminates. This issue does not occur in Linux so it appears Windows specific.
The error is likely due to the JVM locking this file once the DLL file is loaded, but I was unable to find documentation regarding why it happens.
Here is the full stack trace in case it helps:
Exception in thread "Thread-1" java.lang.RuntimeException: java.nio.file.AccessDeniedException: C:\Users\Michael\AppData\Local\Temp\5989570558901519688\nu\pattern\opencv\windows\x86_64\libopencv_java249.dll
at nu.pattern.OpenCV$TemporaryDirectory.delete(OpenCV.java:146)
at nu.pattern.OpenCV$TemporaryDirectory$1.run(OpenCV.java:117)
Caused by: java.nio.file.AccessDeniedException: C:\Users\Michael\AppData\Local\Temp\5989570558901519688\nu\pattern\opencv\windows\x86_64\libopencv_java249.dll
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.implDelete(Unknown Source)
at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(Unknown Source)
at java.nio.file.Files.deleteIfExists(Unknown Source)
at nu.pattern.OpenCV$TemporaryDirectory$2.visitFile(OpenCV.java:141)
at nu.pattern.OpenCV$TemporaryDirectory$2.visitFile(OpenCV.java:1)
at java.nio.file.Files.walkFileTree(Unknown Source)
at java.nio.file.Files.walkFileTree(Unknown Source)
at nu.pattern.OpenCV$TemporaryDirectory.delete(OpenCV.java:130)
The text was updated successfully, but these errors were encountered: