-4

Heres my code please help! I'm making a launcher for my game. I want to be able to launch the game from the launcher but it dosent work.

ProcessBuilder pb = new ProcessBuilder("test.jar","C:/Users/Marcus/Documents/");
            try {
                pb.directory(new File("C:\\"));
                Process p = pb.start();
            } catch (IOException e) {
                e.printStackTrace();
            }

error:

java.io.IOException: Cannot run program "test.jar" (in directory "C:\"): CreateProcess error=2, Cant find the file  at java.lang.ProcessBuilder.start(Unknown Source)
Undo
  • 25,519
  • 37
  • 106
  • 129
MCrafterzz
  • 51
  • 1
  • 7

1 Answers1

0

Your test.jar is relative that's why i cannot find the it. You have to specify the path to test.jar

Then you should check if your jar is executable. If not you will need to add java to the list of arguments when creating the ProcessBuilder.

Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82