Перезапустите Java-приложение в Ubuntu
Какой лучший способ перезапустить приложение Java в Ubuntu? Я знаю, что вы можете запускать такие команды из терминала, но, похоже, это не работает.
2 ответа
Вы убиваете родительский процесс с помощью System.exit(1), поэтому его дочерний процесс также уничтожается. Для перезапуска вы обычно предоставляете оболочку сценария оболочки для запуска реального приложения Java.
Обратите внимание, что приведенный выше код представляет собой грубую, грубую схему. Типичные обертки гораздо сложнее иметь дело с аргументами командной строки, передаваемыми самому сценарию запуска и т. Д. И т. Д. Кроме того, мои навыки sh не являются безошибочными.
Linux restart Java service (super simple, with automatic restart Java program shell script)
Small knowledge, big challenge! This article is participating in the creation activity of «Essential Tips for Programmers».
I was recently asked in a study group by an older man who needed to restart a microservice but had no previous experience with Linux, just development. I just wonder how many trained to work for a year or two all have no contact with the company’s servers, even don’t know the company where the server is, only know their own written code submitted, and then test no problem don’t know anything about the project follow-up, so I want to write a super easy to restart a Java program posts everybody progresses together.
The environment
System: Ali Cloud Center OS 8 Java environment: JDk1.8 Java program: Hg-learn.jar \
The first step
Check whether the current Java program is running
ps -ef|grep hg-learn.jar
The second step
You can run the preceding command to view the running status of the Hg-learn. jar jar package. The process ID is 78572. You can also run the kill + command to kill the process
How can I reload java module
We need to use java 11 so we build it the way we did.
We want to find a way to reload java jdk in the following without restarting.
We would like to replace shutdown -r with some type of source or something in the following:
Because after a restart java -version shows openjdk version ‘11.0.1″ 2018-10-16
What would do that?
1 Answer 1
Rebooting should not be necessary.
Your sudo update-alternatives —config java command actually does most of the job of switching the default from one version of Java to the other. However, after that command, you might need to run hash -r to get the shell of the current session to forget its old idea of where the various executables actually are and start afresh. If the java command was used while the version 10.0.1 was still the latest one installed, the shell might have cached its location and keep using it until told otherwise, with either hash -r , logout/login, or a reboot (which is overkill for this purpose).
If your friend has added something in the login scripts that explicitly sets $JAVA_HOME or any other relevant environment variables, then logging out and back in might be necessary too.
So, I’d suggest the following procedure:
You must log in to answer this question.
-
The Overflow Blog
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.6.16.43501
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
restart java app in ubuntu
What’s the best way to restart a java app in ubuntu? I know u can run commands like this one from the terminal, but it doesnt seem to be working.
2 Answers 2
You are killing the parent process with System.exit(1), so its child process is destroyed as well. To restart you would typically provide a shell script wrapper to launch the actual Java app.
Note the above code is a rough, crude outline. Typical wrappers are far more complex to deal with commandline arguments passed to the startup script itself etc. etc. Plus, my sh-skills are not infallible.