Start the Jar package in the Linux environment

Run the Jar package directly through the command line
Enter the following command in the terminal:

java -jar YourJarFileName.jar

Among them, YourJarFileName.jar indicates the file name of the Jar package to be started. After executing this command, the program will run in the foreground and output log information. If you need to close the program, you can press CTRL + C to interrupt the program.

Run the Jar package in the background through a script
You can start the Jar package by writing a script and make the program run in the background.

Create a startup script file, such as named startup.sh, and add the following content to the script:

#!/bin/bash
nohup java -jar YourJarFileName.jar > log.file 2>&1 &

Among them, YourJarFileName.jar indicates the file name of the Jar package to be started, log.file is the log output file, 2>&1 indicates redirecting the standard error output (stderr) to the standard output (stdout), and the & symbol indicates running the file in the background Order. Using this command will open a new process to run the program without affecting the use of the current terminal.

Finally, enter the directory where the script is located through the terminal, and run the following command to start the program:

sh startup.sh

The program will run in the background, if you need to stop the program, you can use the following command:

ps -ef|grep YourJarFileName.jar|grep -v grep|cut -c 9-15|xargs kill -s TERM

Among them, YourJarFileName.jar indicates the file name of the Jar package to be stopped. Run the above command to end all processes of the program.

Guess you like

Origin blog.csdn.net/Mr_Dong_cson/article/details/129400040