0

I have a java-based application launcher that uses ProcessBuilder (have tried Runtime.getRuntime().exec(new String[]{} as well) that launches another java application via a command.

When I run the command manually, it works properly. The game launches, no errors.

java -jar -Djava.library.path="./lib/natives" mygame.jar

When the same command (with absolute paths) is run from the launcher:

ProcessBuilder pb = new ProcessBuilder(
        "java",
        "-jar",
        "-Djava.library.path=\"" +nativesDirectory.getAbsolutePath() + "\"",
        applicationJar.getAbsolutePath());
pb.redirectErrorStream(true);
pb.directory(applicationDirectory);

I see the following error:

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

I've tried multiple variations but it just seems like the command will never properly set the library path when being run from the java launcher.

  1. Is there anything else I can try? Why would the command work for me, but not the launcher? I've tried the ProcessBuilder because I was worried it might be problems with spaces in the file paths (despite having quotes around it)

  2. Is there a better way to let my application dictate/discover where the libs/native files are, avoiding having to always pass the argument anyway?

2
  • What happens if you remove the quotes around the path? The quotes are parsed by the shell and are not necessary when spawning a process directly from Java. Commented Nov 11, 2013 at 7:01
  • 1
    That solved it... holy cow. If you want to move this to an answer I'll mark it. I can't believe no one else I've spoken to suggested that, myself included. Commented Nov 11, 2013 at 7:08

2 Answers 2

2

Alternatively you can add path to the native library to PATH env variable thru ProcessBuilder.environment()

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

1 Comment

Thanks, gave it a try but nothing changed. I appended the natives directory to the existing path, and then add it via pb.environment().put("PATH", fullPath);. I even iterated the pb.environment map to confirm. Same error on startup. Tried the path with and without the quotes.
1

What happens if you remove the quotes around the path? The quotes are parsed by the shell and are not necessary when spawning a process directly from Java.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.