Portal Home > Knowledgebase > Articles Database > Running a jar file in the background on Linux
Running a jar file in the background on Linux
Posted by That Guy, 08-21-2007, 08:29 PM |
I have a server that's made in Java. However, when I run it I have to keep the console window open which kind of defeats the purpose of running it on a remote server if my computer has to stay on as well. I can run it in the background at least, but the console window my stay up. Is there a way it can run without my console window open? Is making it a service the only way?
|
Posted by Dougy, 08-21-2007, 08:34 PM |
Run it under screen?
screen ./program or screen application
press ctrl + a, then d
|
Posted by cywkevin, 08-21-2007, 08:34 PM |
I would probably use screen to do this. Same time ftw.
You can also add the -S parameter to give your screen a personal name.
|
Posted by That Guy, 08-21-2007, 08:35 PM |
How can I do that? It's a .jar file, so I usually start it with java -jar server.jar &
|
Posted by cywkevin, 08-21-2007, 08:38 PM |
You don't have to start the program in the screen startup.
For example you could just type screen to start a new session.
Run the jar application like you normally would and then detach the screen.
|
Posted by That Guy, 08-21-2007, 08:40 PM |
Mm...how would I do that? Sorry, I'm a bit of a linux noob so you'll have to spell everything out.
|
Posted by Dougy, 08-21-2007, 08:41 PM |
screen java -jar server.jar &
Press ctrl + a, then d
Done.
|
Posted by That Guy, 08-21-2007, 08:49 PM |
Mm...I'm on a mac, so when I did ctrl + a then d, nothing happened. What's that supposed to do? Anyway, it worked.
|
Posted by RSkeens, 08-21-2007, 09:15 PM |
Darn you beat me to it
That should work for you Mike - I have used that same method for Java programs that I have run on a shell account.
|
Posted by rasputinj, 08-22-2007, 01:32 AM |
I always suggest knowing how to run and compile java and jar programs from the command line, before using a GUI.
|
Posted by That Guy, 08-22-2007, 04:43 PM |
Well, since I'm running this on a server I'm never going to use a GUI.
|
Posted by devonblzx, 08-22-2007, 05:00 PM |
You wouldn't need the & if you were running it in a screen, would you?
screen -A -m -d -S screenname java -jar server.jar
Would start it and detach the screen automatically, then type screen -r screenname to get back into it.
|
Add to Favourites Print this Article
Also Read