I've looked at tons of different StackOverflow questions, and articles on other websites, but none of them have exactly what I'm looking for.
What I'm attempting to do:
I have a program that needs to sleep for a while, and then check to make sure that a program is still running, then sleep again. I've gotten that part done all fine and dandy, but I'm running into a problem making it run in the background. I'm trying to get it to run with no system tray, no command prompt window, just a process. Is there any way I can do this? It really annoys me having to have a command prompt window open 24/7 for a program as simple as this one, and if anyone could help it would be great!
(Also, note that I'm not talking about compiling from command line, I'm saying after you open the .exe version of the java program, how you could make it open the exe without a command prompt window or GUI)
Thanks!
EDIT: Yes, I am running Windows, and this program will be run solely on Windows OS'.
Another option would be to open Task Manager, switch to the "Startup" tab and change the java update program from enabled to disabled. That will take effect starting next time you boot your computer.
Select Start , then select Settings > Privacy > Background apps. Under Background Apps, make sure Let apps run in the background is turned On. Under Choose which apps can run in the background, turn individual apps and services settings On or Off.
Exit a Java Method using Returnexit() method in java is the simplest way to terminate the program in abnormal conditions. There is one more way to exit the java program using return keyword. return keyword completes execution of the method when used and returns the value from the function.
What you want is a daemon program. The Windows equivalent of a daemon is a Windows Service.
So one solution is to run your program as a Windows Service. It's very simple to convert a command line java program into a service with ProcRun. I just did this last week with a particular program I had - took around half a day, mainly because it was the first time I was doing it.
Making it a Windows Service has the advantage that you can set it to start automatically when the machine boots.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With