为什么它会锁定lib / modules? [英] Why does it keep lib/modules locked?

查看:153
本文介绍了为什么它会锁定lib / modules?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我启动任何第三方应用程序时,例如记事本(但你可以采取其他任何东西),从Java 9应用程序,然后退出Java应用程序:

When I launch any third-party application, e.g. Notepad (but you could take anything else), from a Java 9 application and then exit the Java application:

import java.io.*;

public class LaunchNotepad {
  public static void main(String[] args) throws IOException {
    Runtime.getRuntime().exec(new String[] {"C:\\Windows\\notepad.exe"});
  }
}

推出的第三方应用程序一直锁定Java 9的 lib\modules 文件。这使得我们的Java应用程序很难使用私有JRE进行自我更新,因为无法重命名原始目录(包含JRE)。这是ProcessExplorer(Sysinternals)的截图:

the launched third party application keeps locking Java 9's lib\modules file. This makes it hard for our Java application with a private JRE to update itself, because the original directory (containing the JRE) can't be renamed. Here's a screenshot from ProcessExplorer (Sysinternals):

这有点像Java 9的bug(报告为 JDK-8194734 ),但可以解决在Windows上启动应用程序而无需锁定 lib\modules 文件,例如通过使用外部(代理)应用程序简单地将传递的参数作为应用程序启动?

This smells like a Java 9 bug (reported as JDK-8194734), but is there a work-around for launching an application on Windows without locking the lib\modules file, e.g. by using an external (proxy) application that simply launches the passed parameter as an application?

推荐答案

解决了这个错误。这算作解决方法吗? :)

I fixed this bug. Does this count as a workaround? :)

否则,确实可以采用一些解决方法。

Otherwise, some workarounds are indeed possible.

解决方法1:使用awt.Desktop

通过Java源代码扫描,我发现 awt.Desktop 可以调用 ShellExecute for us。

Scanning through the Java sources, I found that awt.Desktop can call ShellExecute for us.

不幸的是,此方法不允许传递命令行参数。您可以将临时批处理文件写入磁盘并将其作为解决方法启动。

Unfortunately, this method does not allow to pass commandline arguments. You can write a temporary batch file to disk and launch it as workaround.

import java.io.*;
import java.awt.Desktop;

public class LaunchNotepad {
  public static void main(String[] args) throws IOException {
    File program = new File("C:\\Windows\\notepad.exe");
    Desktop.getDesktop().open(program);
  }
}

解决方法2:使用PsExec作为代理

SysInternals PsExec 不会将文件继承到以它开头的进程中。请记住使用 -d 参数,否则PsExec本身将保留该文件。

SysInternals PsExec does not inherit files into processes started with it. Remember to use -d parameter, or PsExec itself will hold the file.

使用 cmd.exe 作为代理是不可能的,因为它总是继承句柄。

Using cmd.exe as proxy is not possible, because it always inherits handles.

解决方法3:创建自己的代理

您将需要使用两个WINAPI中的一个: CreateProcess (指定 bInheritHandles = FALSE )或 ShellExecute

You will need to use one of two WINAPI's: CreateProcess (specifying bInheritHandles=FALSE) or ShellExecute.

这篇关于为什么它会锁定lib / modules?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆