java - 使用应用服务器运行.exe

标签 java glassfish runtime

可以将 .exe 文件打包到 java jar 中,并将此 jar 添加到项目的部署程序集中,然后使用以下命令运行此 exe:

Runtime.getRuntime().exec(); 我试图通过使用类加载器获取 glassfish 域内的路径后运行此 exe,但实际上此 exe 打包在 jar 内,这阻止了 Windows 执行它。

最佳答案

您必须首先从 jar 中提取它:

    FileOutputStream fos=null;
    InputStream is = null;
    try
    {

        is = this.getClass().getResourceAsStream("path to your exe inside the jar");
        fos = new FileOutputStream("destination path on host file system");
        byte[] buffer = new byte[1024];
        int read;
        while ((read = is.read(buffer)) > -1)
            fos.write(buffer, 0, read);

    }
    finally
    {

        if (is != null)
            is.close();
        if (fos != null)
            fos.close();
    }

然后,使用 Runtime.getRuntime().exec() 在主机文件系统上运行它.

关于java - 使用应用服务器运行.exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25690538/

相关文章:

java - 需要一些帮助才能通过 setText 问题将变量从 fragment X 传递到 fragment Y

java - 奇怪的问题 - Glassfish 3.1.1 Server 和 Eclipse Indigo

c# - 在运行时加载引用调用程序集的程序集

ios - 在 Swift 运行时从闭包中获取参数信息

java - 设置可绘制对象后如何获得默认编辑线颜色?

java - 插件开发的 Maven 依赖

java - 使用.class文件而不是android gradle中的.java文件构建sources.jar

java.lang.NoSuchMethodError : javax. ws.rs.core.Application.getProperties()Ljava/util/Map

java - apache tomcat 和 glassfish 服务器不解码 utf-8 字符?

Android 运行时布局教程