Social Media

procrun – Java Programs as Windows Services

I recently needed to run a Java program as a Windows service, and opted for Commons-daemon procrun. This wrapper is used by both Tomcat and JBoss Wildfly to wrap their servers – but took a bit of figuring out how to get my application running.

This post sets out an example of using procrun to wrap a Java process.


I downloaded procrun from download. The download contains 3 different version of the procrun.exe –

  • 32 bit – this is the default architecture
  • amd64 – 64-bit AMD architecture
  • ia64 – 64-bit Intel Itanium architecture

You need to use the right version for your JVM and chipset


The code is based on the EchoServer and EchoClient examples from oracle.



The client is changed to take a shutdown parameter –


Ive also created a simple class to stop and start the server –

Putting it all together –

  1. Add the above classes and procrun.exe to a directory – C:\procrun
  2. Compile – javac *.java
  3. Create Archive – jar cvf simpleechoserver.jar *.class *.jar


You dont need to create a service.bat file – but its cleaner and simpler. Store this in your code directory.

Key Points

  • All the Procrun fields are marked with PR_ – you can also feed these fields directly to procrun.exe using the ++ or — notation in the procrun notes, but i think this way is cleaner and easier to maintain
  • The key ones are the start/stop fields
  • PR_JVMOPTIONS – allows us to pass system properties to the Windows Service
  • Installing and removing –
  • There are other “//” options defined in the notes

Running service.bat

You may need to run this as administrator –

To install –

And uninstall –

You can then test –

If you go to your Windows Services you will now see SimpleEchoServer with stop/start/restart options


The final trick is to use prunmgr. This the the procrun manager and allows you to see the procrun operating parameters. To get started go to your copy of prunmgr.exe and rename or copy it to the SERVICE_NAME in your batch file

So –

You then run the SimpleEchoServer.exe as administrator –



About the Author Martin Farrell

My name is Martin Farrell. I have almost 20 years Java experience. I specialize inthe Spring Framework and JEE. I’ve consulted to a range of businesses, and have provide Java and Spring mentoring and training. You can learn more at About or on my consultancy website Glendevon Software

follow me on:

Leave a Comment:

Spring Boot as a Windows Service in 5 minutes - javabullets says 06/12/2017

[…] service and am surprised how easy it was using winsw. I’d previously written about using procrun – Java Programs as Windows Services, but winsw is much […]

Spring Boot as a Windows Service in 5 Minutes | simple note says 19/12/2017

[…] Windows service and am surprised how easy it was using winsw. I’d previously written about using procrun – Java Programs as Windows Services, but winsw is much […]

Rodolfo Miranda says 13/09/2019

Great help!
Just a note, that kept me running in circles for a couple of hours:

The current version of procrun does not have the IA64 exe version anymore.

I was using the prunsrv.exe file trying to run a java file compiled with 64-bit JDK and (now I see it) obviously the service could not run. Windows Service manager kept saying “Incorrect function” when trying to start it. Until I checked my local logs, I saw that the error was ” %1 is not a valid Win32 application.” and “Failed creating Java ‘C:\jdk8\jre\bin\server\jvm.dll’.”

I switched to the prunsrv.exe that was shipped in the amd64\ folder, and everything worked like a charm.

zeroC says 04/11/2019

I implemented as above
But, an error occurred “ Connection refused: connect”.
I using java 10.
How to resolve that.
Please help me.

Add Your Reply