Not able to run java code in the background using sh file

85 Views Asked by At

My SH file:

#!/bin/bash

DIR="$(dirname "$(readlink -f "$0")")/"

cd "$DIR"

javac -cp "streamer-client-java.jar:kafka-clients-3.4.0.jar:lz4-java-1.8.0.jar:slf4j-api-2.0.7.jar:snappy-java-1.1.10.0.jar:." EnduserCredentialExample.java

java -cp "streamer-client-java.jar:kafka-clients-3.4.0.jar:lz4-java-1.8.0.jar:slf4j-api-2.0.7.jar:snappy-java-1.1.10.0.jar:." EnduserCredentialExample.java

echo "JAVA_KAFKA script running now"

The above code is my SH script, and I'm not able to run it in the background.

We tried it using the following command:

nohup java -cp "streamer-client-java.jar:kafka-clients-3.4.0.jar:lz4-java-1.8.0.jar:slf4j-api-2.0.7.jar:snappy-java-1.1.10.0.jar:." EnduserCredentialExample.java > output.log 2> error.log &

java -cp "streamer-client-java.jar:kafka-clients-3.4.0.jar:lz4-java-1.8.0.jar:slf4j-api-2.0.7.jar:snappy-java-1.1.10.0.jar:." EnduserCredentialExample.java > /dev/null 2>&1 &

If I run this command, it triggers the script, and the script starts running, but after 5 seconds, the script stops running.

java -cp "streamer-client-java.jar:kafka-clients-3.4.0.jar:lz4-java-1.8.0.jar:slf4j-api-2.0.7.jar:snappy-java-1.1.10.0.jar:." EnduserCredentialExample.java

If I run this command without nohup and /dev/null 2>&1 & manually in the terminal, and it's working fine. How can I run this in the background?

0

There are 0 best solutions below