0

Trying to build a basic launcher for a java game. I'm building the proper command to run the application. When the following command executes in the launcher, the launcher closes as expected, but the command doesn't appear to work - either it doesn't work or the game launches and immediately crashes.

When I print this same command to the console and copy/paste it into console and execute manually, it works perfectly.

/** * */ protected void launch(){ currentStatusMsg = "Launching..."; String cmd = "java -jar"; cmd += " -Djava.library.path=\"" +nativesDirectory.getAbsolutePath() + "\""; cmd += " \""+applicationJar.getAbsolutePath() + "\""; System.out.println(cmd); try { Runtime rt = Runtime.getRuntime(); Process pr = rt.exec(cmd); //closeLauncher(); BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream())); String line=null; while((line=input.readLine()) != null) { System.out.println(line); } int exitVal = pr.waitFor(); System.out.println("Exited with error code "+exitVal); } catch(Exception e) { System.out.println(e.toString()); e.printStackTrace(); } } 

I tried adding something to read the output, but nothing is printed.

I was originally using the following format instead, but it has the same effect:

Process pr = Runtime.getRuntime().exec(new String[]{ "java", "-Djava.library.path=\"" +nativesDirectory.getAbsolutePath() + "\"", "-jar", applicationJar.getAbsolutePath()}); 

Update I realized I was closing the launcher before allowing the debug code to run. The system only prints: "Exited with error code 1"

I finally was able to get the subprocess error to print. It states:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path

However, it should be available because the command I'm executing includes the library path, and when this exact command is run manually, it works fine.

1 Answer 1

1

the java command launcher is not a shell. don't use quoting and space separated commands because it won't end well. put each argument into a separate String without any extra quoting, and use the exec(String[]) method.

Sign up to request clarification or add additional context in comments.

3 Comments

Will the quotes be handled automatically, because often times paths have spaces in them.
I've updated the post. I had used the String[] originally but it has the same result.
@BotskoNet - you only need quoting when you are using a shell, that's why i indicated that you should remove all the quotes (which is why the library path is still not working).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.