Oct 07 2010

Commons Daemon Procrun as a Java Service Wrapper for ActiveMQ

Category: ActiveMQRussell Pitre @ 9:58 pm

Apache Commons Daemon consists of two parts for managing daemon processes on both Unix and Windows systems. The first of two is a C library for interacting with the operating system and the second part is a Java API for interacting with the daemon. On Windows systems the C part is called Procrun and we’ll be using it to create a service wrapper for Apache ActiveMQ. Procrun consists of two executables prunsrv.exe and prunmgr.exe. The later is GUI application to manage the windows service after it has been installed.

I was lead to Procrun while setting up ActiveMQ on Windows 2008 server 64-bit. ActiveMQ ships with the popular java service wrapper by Tanuki Software but the community version of the wrapper isn’t available for 64-bit versions of windows.

If you do go ahead and install the service wrapper that ships with ActiveMQ you’ll see this warning in the wrapper.log file after starting the ActiveMQ service.

 WARNING - Unable to load the Wrapper's native library 'wrapper.dll'.
           The file is located on the path at the following location but
           could not be loaded:
           Please verify that the file is readable by the current user
           and that the file has not been corrupted in any way.
           One common cause of this problem is running a 32-bit version
           of the Wrapper with a 64-bit version of Java, or vica versa.
           This is a 64-bit JVM.
           Reported cause:
             C:\JAVA\apache-activemq-5.3.1\bin\win32\wrapper.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
           System signals will not be handled correctly.

I’m assuming you have already downloaded and extracted ActiveMQ.

Download native binaries

First, you’ll need to download Commons Daemon native binaries and then extract the zip file.

Copy and Rename

Navigate to the folder specific to the architecture of the OS your installing the service on, in my case it was amd64. Copy prunsrv.exe to ACTIVEMQ_HOME/bin and then rename the .exe to ActiveMQ.exe. This file is the service wrapper executable Windows will launch when the OS boots up. Next is to copy prunmgr.exe to ACTIVEMQ_HOME/bin and rename that to ActiveMQw.exe. Whatever name you choose for renaming prunsrv.exe to, make sure to rename prunmgr.exe to the same name with ‘w’ appended. This is the executable to configure and manage the windows service after it has been installed.

Install Service

Open a command prompt in Administrator mode by right-clicking and selecting “Run as Administrator”, this may only be specific to Server 2008. Navigate to ACTIVEMQ_HOME\bin where you copied the executables to. Run the following command substituting the path of your installation of ActiveMQ:

C:\Java\apache-activemq-5.4.1\bin>ActiveMQ.exe //IS//ActiveMQ 
		\ --DisplayName="Apache ActiveMQ" 
		\ --Description="Apache ActiveMQ Java Messaging Server" 
		\ --Startup=auto 
		\ --LogPath=C:\Java\apache-activemq-5.4.1\logs 
		\ --LogLevel=INFO 
		\ --LogPrefix=activemq-daemon 
		\ --StdOutput=auto 
		\ --StdError=auto 
		\ --StartPath=C:\Java\apache-activemq-5.4.1 
		\ --StartClass=org.apache.activemq.console.Main 
		\ --StartMethod=main 
		\ --StartParams=start
		\ --StartMode=jvm 
		\ --StopPath=C:\Java\apache-activemq-5.4.1 
		\ --StopClass=org.apache.activemq.console.Main 
		\ --StopMethod=main 
		\ --StopParams=shutdown 
		\ --StopMode=jvm 
		\ --Jvm=C:\Java\jdk1.6.0_18\jre\bin\server\jvm.dll 
		\ --Classpath=C:\Java\apache-activemq-5.4.1\bin\run.jar 
		\ --JvmOptions=-Xmx512M 
		\ ++JvmOptions=-Dorg.apache.activemq.UseDedicatedTaskRunner=true 
		\ ++JvmOptions=-Djava.util.logging.config.file=logging.properties 
		\ ++JvmOptions=-Dactivemq.home=C:\Java\apache-activemq-5.4.1 
		\ ++JvmOptions=-Dactivemq.base=C:\Java\apache-activemq-5.4.1 
		\ ++JvmOptions=-Dactivemq.classpath=C:\Java\apache-activemq-5.4.1\conf 
		\ ++JvmOptions=-Dcom.sun.management.jmxremote.port=9004 
		\ ++JvmOptions=-Dcom.sun.management.jmxremote.authenticate=false 
		\ ++JvmOptions=-Dcom.sun.management.jmxremote.ssl=false

The above command should get you 90% of the way there to a fully configured ActiveMQ windows service. The last 10% of configuration may be easier with the GUI in a trial and error scenario.


Launch the service manager (the executable you renamed ending with ‘w’) in Administrator mode. Below are the screenshots of each of the tabs in the service manager of fully configured ActiveMQ windows service.








The above screenshot of the shutdown tab is misconfigured, use these as the arguments instead adjusting the jmx port if needed:


11 Responses to “Commons Daemon Procrun as a Java Service Wrapper for ActiveMQ”

  1. Carl Verbiest says:

    Works fine on Windows 2008 R2.
    I did have to join all lines of the install command to a single line.

    You can uninstall the service using
    C:\Java\apache-activemq-5.4.1\bin>ActiveMQ.exe //DS//ActiveMQ

  2. Allen says:

    There is a patch to make activemq interact with commons daemon nicer:


  3. Radheshyam says:

    Easy to go install and start service.

  4. James Black says:

    We are seeing the following error when shutting down the application:

    Error 109: The pipe has been closed.

    Any idea how to address this?
    This is when using the start up/shutdown method of JVM.

  5. rambo says:

    It was nice information.
    But as I download the binary ex(commons-daemon-1.0.6-bin-windows.zip), after extracting it i dint find procrun.exe in that.
    It has
    folder called apidocs
    commons-daemon-1.0.6 jar file
    commons-daemon-1.0.6-javadoc jarfile
    commons-daemon-1.0.6-sources jar file.
    Where can I get that.

  6. pete says:

    Great article! Thank you for posting this.

  7. Frikkie says:

    Excellent, running on Windows Server 2008 R2.
    Used the prunsrv.exe in the amd64 directory.
    Very clear and easy to follow guide, thank you.
    Saved me hours.

  8. qt4x11 says:

    I was able to install ActiveMQ as a service using the instructions in this article, however when I start it up via the Service control panel I get

    Windows could not start the ActiveMQ on the local computer. For more information, review the System Event Log.

    When I check the Event Log I see

    The ActiveMQ service terminated with service-specific error The operation completed successfully..

    I think this may be related to my architecture. I’m running Windows server 2008 R2, my processers are 64 bit Intel Xeon. I did not see that architecture included in the commons-daemon package. When I installed, I used the generic ‘prunsrv.exe’ file instead of the amd64/prunsrv.exe, or the ia64/prunsrv.exe – I received errors when I tried to use these exe files during installation, and was only able to install using the generic prunsrv.exe.

    Is there a way to get this to work with my architecture? or did I miss anything?

  9. hari janardhan says:

    To run as a service, of course you need to double click on InstallService batch file which is under the win32 folder.

  10. Bill Harts says:

    I’m having some problem, hope someone can help. I am able to start from the activemq.bat file in a cmd window with no problem.

    I followed all the steps very carefully, but when I try to start the service from prunmgr (renamed as ActiveMQw.exe), I get the following:

    2013-07-10 01:41:06 Commons Daemon procrun stderr initialized
    java.lang.NoClassDefFoundError: org/apache/activemq/console/Main
    Caused by: java.lang.ClassNotFoundException: org.apache.activemq.console.Main
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    Exception in thread “main”

    Here’s the .bat file I used to install:

    ActiveMQ.exe //IS//ActiveMQ ^
    –DisplayName=”Apache ActiveMQ” ^
    –Description=”Apache ActiveMQ Messaging Server” ^
    –Startup=auto ^
    –LogPath=”C:\Program Files\apache-activemq-5.8.0\logs” ^
    –LogLevel=INFO ^
    –LogPrefix=activemq-daemon ^
    –StdOutput=auto ^
    –StdError=auto ^
    –StartPath=”C:\Program Files\apache-activemq-5.8.0″ ^
    –StartClass=org.apache.activemq.console.Main ^
    –StartMethod=main ^
    –StartParams=start ^
    –StartMode=jvm ^
    –StopPath=”C:\Program Files\apache-activemq-5.8.0″ ^
    –StopClass=org.apache.activemq.console.Main ^
    –StopMethod=main ^
    –StopParams=shutdown ^
    –StopMode=jvm ^
    –Jvm=”C:\Program Files\Java\jdk1.7.0_25\jre\bin\server\jvm.dll” ^
    –Classpath=”C:\Program Files\apache-activemq-5.8.0\bin\run.jar” ^
    –JvmOptions=-Xmx512M ^
    ++JvmOptions=-Dorg.apache.activemq.UseDedicatedTaskRunner=true ^
    ++JvmOptions=-Djava.util.logging.config.file=logging.properties ^
    ++JvmOptions=-Dactivemq.home=”C:\Program Files\apache-activemq-5.8.0″ ^
    ++JvmOptions=-Dactivemq.base=”C:\Program Files\apache-activemq-5.8.0″ ^
    ++JvmOptions=-Dactivemq.classpath=”C:\Program Files\apache-activemq-5.8.0\conf” ^
    ++JvmOptions=-Dcom.sun.management.jmxremote.port=9004 ^
    ++JvmOptions=-Dcom.sun.management.jmxremote.authenticate=false ^

    Any ideas? Maybe the working directory should include /bin?


Leave a Reply