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.

0

2 Answers 2

1

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

java -cp /.../.../....jar ClassWithMain &
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.