0

I am making a game in lwjgl, and I exported the jar for it. I put all the natives in the same folder as it, and if you click the jar it runs fine. However, if I do

ProcessBuilder pb = new ProcessBuilder("java", "-Djava.library.path="+pathtonativefolder, "-jar", pathtojar);

Then it doesn't launch. However, when I do

java -Djava.library.path=nativesfolder -jar thejar.jar

It works fine. What's happening? I assume it's not setting the java.library.path correctly.

ByteDuck
  • 1,821
  • 3
  • 15
  • 27
  • The `jar` must be followed by a jar, you can't but the `-D` after the `-jar`. – Elliott Frisch Apr 11 '15 at 20:05
  • @ElliottFrisch It still doesn't work if I change it to ProcessBuilder pb = new ProcessBuilder("java", "-Djava.library.path="+pathtonativefolder, "-jar" ,pathtojar); – ByteDuck Apr 11 '15 at 20:07
  • The command you build is not the command that works. Also, consider giving full path to java binary. – Thorbjørn Ravn Andersen Apr 11 '15 at 20:14
  • Maybe the native code is sensitive to the current working directory? Does it work if you use `pb.directory` to set the cwd for the command to the same value as when you run it from the command line? – Ian Roberts Apr 11 '15 at 20:19
  • @IanRoberts Nope, that doesn't work either. – ByteDuck Apr 11 '15 at 20:24
  • What Exception or output do you get when you start the process? Are you using [`inheritIO`](https://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html#inheritIO%28%29)? – Elliott Frisch Apr 11 '15 at 20:47
  • Maybe a silly question, but you do call [`pb.start()`](http://docs.oracle.com/javase/8/docs/api/java/lang/ProcessBuilder.html#start--), don't you? – siegi Apr 11 '15 at 21:56
  • @siegi :P yes I do. Thanks for asking though. – ByteDuck Apr 11 '15 at 22:16
  • @ElliottFrisch I do not get any exceptions or stacktraces, and I am not using inheritIO. Would inheritIO be useful? – ByteDuck Apr 11 '15 at 22:17
  • @user3042719 Did you try `inheritIO` and see [Unsupported major.minor version](http://stackoverflow.com/questions/10382929/how-to-fix-unsupported-major-minor-version-51-0-error)? – Elliott Frisch Apr 12 '15 at 00:18

1 Answers1

0

Actually, I figured out I was trying to launch a Java 1.8 jar from a 1.7 project. Silly me.

ByteDuck
  • 1,821
  • 3
  • 15
  • 27
  • I don't understand why this should not work: You start a new `java` process. The Java version of the original application (i.e. the one calling the `ProcessBuilder`) should not matter, as long as the `java` command points to the correct executable (i.e. the one of Java 8)... Am I missing something? – siegi Apr 11 '15 at 22:38
  • @siegi Well, I changed the project from 1.7 to 1.8 and it worked. I don't know. – ByteDuck Apr 13 '15 at 20:14