ou probably are reading this article because you want to convert a Java application into a Windows service. I can relate. Recently, I wanted to turn a Java server application that embedded the Jetty
web server and ActiveMQ JMS
client into a Windows service, enabling users to start it automatically without logging into the system. Further, I wanted it to start and stop in a controlled fashion. After searching SourceForge for a suitable project to help me fulfill these specific requirements and coming up empty, I decided to write a simple customized solution of my own.
I discovered you can use one of two approaches to convert a Java application into a Windows service:
- The Windows service launches your Java application in a separate process. (The service has no control over the Java application.)
- The Windows service creates a Java virtual machine (JVM) in its own process context and then shuts it down in a controlled manner.
I chose the second approach because it delivered everything I needed. This article describes how to apply this approach when you convert your Java application into a Windows service. It walks you through the development steps while highlighting the core concepts. To follow along, you need to have a good understanding of Windows concepts and the Java Native Interface (JNI) invocation API.