Alex
Alex

Reputation: 39

java: call external jar program (-> 'create process error')

I'm trying toopen/execute another program, which is a .jar file, but I'm getting the following error:

it is not a windows application

(java.io.IOException: CreateProcess error=193)

Here is my code:

import java.io.IOException;

public class Test8 {

    public static void main(String[] args) {

        try {

            String filepath = "C://Users//Alex//Desktop//Speedtest.jar";

            Process p = Runtime.getRuntime().exec(filepath);

        } catch (IOException e) {

            e.printStackTrace();
        }

    }

}

Upvotes: 0

Views: 193

Answers (1)

martinez314
martinez314

Reputation: 12332

At the command-line, JARs are executed with java -jar. Try passing a String array:

String[] args = new String[] {"java", "-jar", "/path/to/myJar.jar"};
Process p = Runtime.getRuntime().exec(args);

Upvotes: 1

Related Questions