I’m in the process of writing a compiled C application which uses the system() function to launch a Java .jar file:
int main() {
system("java -jar MyJar.jar");
return 0;
}
I successfully wrapped this up in a clickable app bundle, however, when I double click it, the application exits immediately before it has a chance to launch the jar. However it works perfectly when I run the compiled C code from the command line.
Any insight would be appreciated!
Scott
The reason the application exits immediately is because of the following line:
You would want to use
execinstead ofsystem. Withexec, your program gets replaced by the Java process and never gets a chance to reach thereturn 0;line. However, it’s much easier to just replace the entire C progrma with a shell script:As written, there is no drawback to this approach that I can think of. The C program already spawns a shell process (that’s what
systemdoes), so why not start out with a shell process in the first place?Lots of application bundles use shell scripts to do things like this.