【问题标题】:Include an exe-file into jar and run it将exe文件包含到jar中并运行它
【发布时间】:2016-11-18 20:56:18
【问题描述】:

我试图将一个 exe 文件包含到一个 jar 应用程序中并运行它。这个想法是首先将其临时提取,然后运行 ​​temp-exe 文件。怎么做?这就是我所尝试的。有我的代码。由于源文件“ffmpeg.exe”而发生异常java.io.FileNotFoundException。我验证了,但是文件包含,目录是正确的。

package extractffmpeg;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;
import org.apache.commons.io.FileUtils;

public class ExtractFFmpeg extends Application {

    public void start(Stage primaryStage) throws IOException, URISyntaxException {
        extractExe();
        System.out.println("extract successfull");
        Platform.exit();
    }

    public static void main(String[] args) {
        launch(args);
    }    

    public void extractExe() throws URISyntaxException, IOException{

        final String resourcesPath = "ffmpeg/ffmpeg.exe";

        URL url = ExtractFFmpeg.class.getResource(resourcesPath);
        File source = new File(url.toString());
        System.out.println("shows url of ffmpeg: " + url.getPath());
        System.out.println("shows file of ffmpeg: " + source);

        File destination = new File("C:/Users/FNI2Abt/Desktop/ffmpeg.exe");

        FileUtils.copyFile(source, destination);
    }
}

【问题讨论】:

  • 使用getResourceAsStream 并编写一个方法,该方法从资源流中重复读取缓冲区,然后将其写入目标直到EOF。

标签: java jar exe


【解决方案1】:

这个想法是创建一个自解压档案。档案应包含 JAR 和 EXE。 JAR 文件应包含一个类,该类将在相邻的 EXE 上调用 Process.exec(...)。

从那里开始,您可以按照本教程进行操作: How do I make a self extract and running installer

【讨论】:

    猜你喜欢
    • 2013-06-08
    • 2010-10-10
    • 2012-09-13
    • 2011-09-18
    • 1970-01-01
    • 1970-01-01
    • 2015-05-17
    • 1970-01-01
    • 2015-03-02
    相关资源
    最近更新 更多