Java Service Wrapper Example

Posted on

Since you're now working with objects, you can use certain methods to get information about the specific object. For example, the following methods are used to get the value associated with the corresponding wrapper object: intValue, byteValue, shortValue, longValue, floatValue, doubleValue, charValue, booleanValue.

Tools > Java Service Wrapper

  • Linux Java Service Wrapper Example This is a simple wrapper to run a Java program as service. You need to be a root user.
  • Since you're now working with objects, you can use certain methods to get information about the specific object. For example, the following methods are used to get the value associated with the corresponding wrapper object: intValue, byteValue, shortValue, longValue, floatValue, doubleValue, charValue, booleanValue. This example will output the same result as the example.

This page provides some useful information on running the ActiveMQ broker as a windows-NT service or a daemon thread in Linux or Unix systems.

64bit 4gb memory limit

The ActiveMQ distribution uses an older and free community release of the service wrapper library. This wrapper has a memory limit of 4gb when running on 64bit platforms. You can manually download a newer release of the wrapper library that does not have this limit, from the vendors website at. It us not possible for Apache ActiveMQ to update and distribute a newer release of the service wrapper, as the vendor changed licensing terms, which does not comply with ASF licensing terms. Therefore out of the box the service wrapper is stuck on that older release.

However you can manually upgrade the library.

Windows-NT Service

Here are the steps to install the ActiveMQ broker as an NT service:

  1. Download the windows binary distribution (i.e. apache-activemq-5.9.0.zip)
  2. Go to ACTIVEMQ_HOME/bin/win32
  3. Run InstallService.bat

After running InstallService.bat, the ActiveMQ service should be added to the list of NT services. It is not started by default.

To verify, go to control panel -> administrative tools -> services and look for the ActiveMQ service. Here you can start the ActiveMQ service or configure it to start automatically every time the system boots.

To remove the ActiveMQ service:

  1. Run UninstallService.bat

Linux/Mac OS X Daemon

Here are the steps to run the ActiveMQ broker as a daemon in Linux or Unix systems:

  1. Download the linux/unix binary distribution (i.e. apache-activemq-5.9.0.tar.gz)
  2. Go to ACTIVEMQ_HOME/linux for linux systems or ACTIVEMQ_HOME/macosx for Mac OS X systems.
  3. Run ./activemq start

To stop the daemon process:

  1. Go to ACTIVEMQ_HOME/linux for linux systems or ACTIVEMQ_HOME/macosx for Mac OS X systems.
  2. Run ./activemq stop

Configuring the Java Service Wrapper

ActiveMQ uses the Java Service Wrapper to run the broker. To configure how the Java Service Wrapper starts up, you can edit the wrapper.conf located in the bin/win32, bin/linux, or bin/macosx depending on which system you are running it. For more information on the different properties of the Java Service Wrapper, refer to this page

Troubleshooting

If you are having problems running the service, turn on the wrapper debugging in the corresponding wrapper.conf file via (wrapper.debug=TRUE)

Yet Another Java Service Wrapper

Each time you run the wrapper, a log file will be created in ACTIVEMQ_HOME/data/wrapper.log

Introduction

Have you ever needed to run your JBoss application server unattended on a Windows machine? There are various ways to accomplish this task. By far, the best alternative is to run the JBoss instance as a Windows service. One of the easiest tools I’ve found for running java-based applications as services is the Java Service Wrapper project from Tanukisoftware.org. According to their website, the Java Service Wrapper is an application which has evolved out of a desire to solve a number of problems common to many Java applications:

  • Run as a Windows Service or Unix Daemon
  • Application Reliability
  • Standard, Out of the Box Scripting
  • On Demand Restarts
  • Flexible Configuration
  • Ease Application Installations
  • Logging

Because it is Java-based and written completely in Java, the Java service wrapper is the perfect candidate for service/daemon enablement of the JBoss server runtime.

Getting Ready

This post specifically deals with the process of confguring JBoss 7 application server as a windows service. You will need to download the following pieces of software before proceeding:

  • JBoss Application Server 7 (download here ) or if you are on the bleeding edge, download the nightly development build from here
  • Java Platform 32-bit standard edition 6+ ( download here )
  • Tanuki Java Service Wrapper 32-bit community edition 3.5.6+ ( download here )
We need the community edition of the java service wrapper (JSW) because the standard and professional editions require purchase of a license. Furthermore, the 64-bit JSW is not available in the community edition. In addition, the 32-bit JSW native library only works with a 32-bit Java Virtual Machine (JVM). So this is why the requirements above are as they are.

Folder Structure

First, you need to create a parent folder which will contain jboss7, the jre and a folder containing the wrapper service files, as depicted in the diagram below:
As you can see, in there, I’ve got 2 different jboss7 distributions, versions 6 and 7 of the jre in case I would like to switch between either of them and a folder called service. With this structure, things are kept clean and separated. If we choose to upgrade the java service wrapper version, we only need to update files in the service folder. If a new version of jboss gets released, we just edit the service configuration to point to the new distribution.

Service Configuration

Now its time to integrate the java service wrapper into our setup. There are four directories that need to be present inside the service folder:

Example
  • bin
  • lib
  • conf
  • logs

Let us call this service folder {SERVICE_HOME}

Unzip the Java service wrapper distribution you downloaded earlier somewhere on your computer. Let us call the directory containing the unzipped distribution {WRAPPER_HOME}.

Copy the following files into service’s bin folder.

2{WRAPPER_HOME}srcbinApp.bat.in
4{WRAPPER_HOME}srcbinUninstallApp-NT.bat.in

Rename the three batch files, substituting App with your applications name, for example. Be sure to remove the .in extensions so that the files all end in .bat.
(Depending on how your file explorer is configured on your computer, you may not be able to see file extensions.)
You should now have:

Java Windows Service Wrapper

2{SERVICE_HOME}binJBoss7_standalone_ha_start.bat
3{SERVICE_HOME}binJBoss7_standalone_ha_install-NT.bat
4{SERVICE_HOME}binJBoss7_standalone_ha_remove-NT.bat

The wrapper.exe is the actual wrapper executable. JBoss7_standalone_ha_start.bat is used to run jboss7 in the console, and it’s Install and Uninstall counterparts are used to install and uninstall the windows service for jboss7 respectively. Notice that these three bat files are named to reflect the mode we choose to run jboss in. To remind ourserlves, the default jboss7 distribution can be run in 4 different modes.

Java Windows Service Wrapper Example

  • standalone
  • standalone-ha (standalone mode with clustering)
  • domain
  • domain-ha (domain mode with clustering)

Create a new set of the 3 bat files for each mode you choose to support. One to start jboss7, one to install jboss7 as a service and another to stop the service in the respective mode as listed above.

Then copy the following files into service’s lib folder. Download docx converter.

2{WRAPPER_HOME}libwrapper.dll

The wrapper.dll file is a native library file required by the portion of the Wrapper which runs within the JVM. The wrapper.jar file contains all of the Wrapper classes.
You should now have.

2{SERVICE_HOME}libwrapper.dll

Now copy the following template for a wrapper.conf file into service’s conf folder

now you should have

1{SERVICE_HOME}confwrapper_standalone_ha.conf

The wrapper_standalone_ha.conf naming easily helps us identify that this configuration file will be used to enable jboss7 as a service in standalone clustering mode. Create corresponding wrapper.conf files for the various jboss7 startup modes that you wish to support e.g. wrapper_domain_ha.conf. Since we are creating various conf files to correspond with the jboss7 startup modes we wish to support, we also need to edit the corresponding bat files created above, to point to the respective wrapper conf file.

Open the corresponding bat files and edit the set_WRAPPER_CONF_DEFAULT default property to point to the required wrapper config file. So for JBoss7_standalone_ha_start.bat, JBoss7_standalone_ha_install-NT.bat and JBoss7_standalone_ha_remove-NT.bat I have changed that property to:

set _WRAPPER_CONF_DEFAULT=./conf/wrapper_standalone_ha.conf

Create a logs directory inside the service directory so you now have

Now it is time to modify your wrapper.conf to tell the java service wrapper how it is supposed to run jboss7 as a service. I have mine below (wrapper_standalone_ha.conf). Notice how the JAVA_HOME, JBOSS_HOME AND SERVICE_HOME variables are set to the locations of the desired java, jboss and service folders, allowing easy switching or upgrading of the corresponding component binaries. We only need to edit the wrapper configuration file and set a new JAVA_HOME if we choose to change the JVM, set a new JBOSS_HOME if we wish to upgrade our server to a new version and set a new SERVICE_HOME if we choose to upgrade the java service wrapper version or even just if we decide to change the name of the service folder (default is called service) or its location.

Putting it all together

JBoss7 can now be run by simply executing the corresponding batch file from {SERVICE_HOME}/bin. Please try running the application once as a console application to verify the configuration before attempting to run it as a service.

Congratulations. Your JBoss7 should now be up and running as a service. 🙂

References: http://wrapper.tanukisoftware.com/doc/english/integrate.html