我们有一个 Java 应用程序,其中包含在 Windows 机器上作为 SYSTEM 运行的组件。在 Windows 7 x64 上,一个组件在尝试解压缩 jnidispatch 库时失败:
Exception in thread "main" java.lang.Error: Failed to create temporary file for
jnidispatch library: java.io.IOException: The system cannot find the path
specified
at com.sun.jna.Native.loadNativeLibraryFromJar(Native.java:600)
at com.sun.jna.Native.loadNativeLibrary(Native.java:550)
at com.sun.jna.Native.<clinit>(Native.java:87)
at falcon.util.vmware.VcmdTwo.loadLibraries(VcmdTwo.java:53)
下面复制了一段来自jna的Native类的注释 图书馆:
When JNA classes are loaded, the native shared library (jnidispatch) is loaded as well. An attempt is made to load it from the system library path using {@link System#loadLibrary}. If not found, the appropriate library will be extracted from the class path into a temporary directory and loaded from there.
好的,到目前为止一切顺利:Java 正在尝试将 jnidispatch.dll 解压到 java.io.tmpdir 指向的任何位置。问题似乎是 java.io.tmpdir 指向该特定进程的 C:\Windows\system32\config\systemprofile\AppData\Local\Temp\。此目录存在且 SYSTEM 具有完全控制权。但是,将 jnidispatch DLL 提取到该目录总是失败。如果我修改应用程序中的代码以手动将文件写入同一目录,则写入成功。
我查看了相关的 Java 和 JDK 代码,没有发现任何明显的不当行为,所以我不得不得出结论,这是一些与 Win7 UAC 相关的奇怪错误,但如果我能弄清楚它是什么,该死的是。欢迎提出任何建议。
最佳答案
您是否 100% 确定它正在写入您认为正在写入的位置?鉴于如果您修改程序以强制它写入到那里并且它可以工作,那么听起来您正在尝试写入另一个目录。
关于java - 在 Win7 上以 SYSTEM 身份运行时写入临时目录失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1925391/