0

I tried to to include an exe-file into a jar-Application and to run it. The idea is to extract it temporary at first and then to run the temp-exe-file. How to do that? That is what I have tried. There is my code. It occurs the exception java.io.FileNotFoundException because of the source file "ffmpeg.exe". I verified, but the file is included and the directory is correct.

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);
    }
}
Vojtech Ruzicka
  • 16,384
  • 15
  • 63
  • 66
Nico
  • 1
  • Use [getResourceAsStream](https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)) and write a method which repeatedly reads a buffer from the resource stream then writes it to destination until EOF. – Adrian Colomitchi Nov 18 '16 at 12:58

1 Answers1

0

The idea is to create a self-extracting archive. The archive shall contain both JAR and EXE. The JAR file shall contain a class which would call Process.exec(...) on the adjacent EXE.

Starting there, you can follow this tutorial: How do I make a self extract and running installer

Community
  • 1
  • 1
alok
  • 502
  • 3
  • 15