Converting Your Java App to a Sevice

You can easily adapt your Java application to a service on Windows. Remember that a service runs in background so if you have an interactive program that you want to run as a service, you must separate the code which interacts with the user from the code which runs independently.

Add public methods called start() and stop() to the java class which contains the main(). The start() function should handle any initialization that your app requires and then start a a private named thread. Of course, it is the responsibility of this thread to keep the program alive.

The start() and stop() methods are invoked when the service is started and stopped. If you also want your application to be started through a regular menu using the main() method, then create a separate launcher.

A service launcher can be used with an updater-on-demand, but not with an auto-updater. If you want an auto-updater for your project, then you must create a separate launcher for an individual to use.

If you have any difficulties install your java app as a service on Windows, look in the \Windows\system32\LogFiles\Apache subdirectory. You'll find a few logs files that might help. If not, send the logs to our support staff for assistance.


There is an example of a simple service, called Hello Service, in the projects directory of JExpress. You'll find the source in the "Hello World/Source subdirectory. You probably want to pay attention to how it uses threads when starting and stopping. Remember that the thread launched in the start() function must keep the code alive. For example, in the HelloService example, the run() has a while which keeps the program running. You'll want something similar in your code.