0
#!/bin/bash 
JAVA_HOME="jdkpath"
CLASSPATH="JAR file path" . 
$JAVA_HOME/bin/java -cp $CLASSPATH JavaClass 
exit 0

I am using the above shell script to call my Java program but I want to make sure that once the shell script calls the Java program, it does not sit idle and wait for the program to complete. I don't know how to do that. I read in an online forum that I can put an "&" symbol at the end of the command where I supply the JAR file path but I am not sure since I am new to shell scripting. All the help is greatly appreciated.

mtrivedi
  • 11
  • 1
  • 1
  • 1

2 Answers2

1

At the end of the shell command, you can put the &. It makes the program run in a subshell.

java -cp /.../.../....jar ClassWithMain &
Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
iil
  • 154
  • 1
  • 3
1

Adding & to the end will send Java to the background. That means that Java will run in the background and the shell script will continue running. But once the shell script reaches the end, it will wait for Java to finish before it exits. You have to disown the java program, and then the script will exit and java will continue to run. Just add the command "disown" directly below where you run the jar file.

kkarayannis
  • 190
  • 8