How to run java program without console

I need to run a java program, even if the terminal is closed. on server....

+4
source share
4 answers

On Unix and GNU / Linux systems, you can run the program using nohup , like this, assuming it's a jar:

 nohup java -jar program.jar & 

To get the program output to a text file, so that later you can view it, you can do:

 nohup java -jar program.jar > program.log & 

There are packages that will port your Java programs to services , which is more manageable than bare java processes.

You might also want to use the wrapper " ( Launch4J , maybe?) To give your process a meaningful name, otherwise all your Java programs will appear as java in the process list, which is not very significant.

+4
source

The "alternative" nohup will be screen . screen very useful and allows you to run any task, disconnect the screen and skip it in the background. You can continue it later.

Task Launch:

 screen <command_you_want_to_run> 

Then <ctrl> <a> <d> to disconnect from the screen session.

The next time you log in, you can re-join the screen session with:

 screen -r 

If you have several screen sessions, you will be presented with their details and can connect to them, for example:

 screen -r 1234.pts-1.hostname 

... where 1234.pts-1.hostname is one of the return values ​​from the screen output -r.

+2
source

Use javaw instead of java .

+1
source

You want to use the silent mode . This will lead to the failure of any calls that try to exchange data with the screen, keyboard, mouse, etc., It also means that you do not need an X server (on Unix) or access to the console (on Windows).

0
source

Source: https://habr.com/ru/post/1314611/


All Articles