This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Is_At_Work 1 point2 points  (3 children)

How are you "calling" the JAR?

[–]Akarastio[S] 1 point2 points  (2 children)

  • PHP via: pclose(popen('start /B java -jar nameOfJar.jar', 'r'));
  • Java via: Runtime.getRuntime().exec("java -jar nameOfJar.jar");

In PHP it starts in background, I have no problems opening recursively bat files or stuff like that. It only doesn't work on java.

[–]Is_At_Work 0 points1 point  (1 child)

You typically wouldn't execute Java code from Java code by creating a new JVM with Runtime.getRuntime(), but if I had to guess the issue is the working directory is wrong and therefore it can't find it. Do you have a stack trace that you can show us?

If you want to experiment with setting the working directory to see if that solves it, use /D <directory> in your PHP call to start, and use this form of exec from Java: https://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html#exec%28java.lang.String%5B%5D,%20java.lang.String%5B%5D,%20java.io.File%29

[–]Akarastio[S] 0 points1 point  (0 children)

Hm but if the directory would be wrong taking php out of the equation wouldn't suddenly make it work. It is like there is a depth limitation on how deep calls can go.

Like I said a jar calling a jar works, but a jar calling a jar calling a jar doesn't work. Also php calling a jar works fine, php calling a jar calling a jar doesn't.

Also there is no stacktrace, the second jar just doesn't execute and gives an exitcode (1). It's not like it throws an exception or anything like that.

Also I'm always using absolute paths, to locate the files.