Java Service Wrapper Tutorial

  

Active1 year, 10 months ago

Each of eight primitive of java data types has a class dedicated to it, are known as wrapper classes, because they wrap the primitive data type into an object of that class. The wrapper classes are part of the java.lang package, which is imported by default into all Java programs. The usual Java Hello World application starts up, prints out Hello World and then exits. That is not very interesting to show off a tool for running and monitoring services. In the case of the Java Service Wrapper, an example which can be installed and then stay running as a Windows Service, or UNIX daemon is required.

I've just inherited a java application that needs to be installed as a service on XP and vista. It's been about 8 years since I've used windows in any form and I've never had to create a service, let alone from something like a java app (I've got a jar for the app and a single dependency jar - log4j). What is the magic necessary to make this run as a service? I've got the source, so code modifications, though preferably avoided, are possible.


19 Answers

sblundysblundy
50.4k21 gold badges112 silver badges119 bronze badges

Apache Commons Daemon is a good alternative. It has Procrun for windows services, and Jsvc for unix daemons. It uses less restrictive Apache license, and Apache Tomcat uses it as a part of itself to run on Windows and Linux! To get it work is a bit tricky, but there is an exhaustive article with working example.

Besides that, you may look at the binservice.bat in Apache Tomcat to get an idea how to setup the service. In Tomcat they rename the Procrun binaries (prunsrv.exe -> tomcat6.exe, prunmgr.exe -> tomcat6w.exe).

Something I struggled with using Procrun, your start and stop methods must accept the parameters (String[] argv). For example 'start(String[] argv)' and 'stop(String[] argv)' would work, but 'start()' and 'stop()' would cause errors. If you can't modify those calls, consider making a bootstrapper class that can massage those calls to fit your needs.


Java Service Wrapper Tutorial

With Apache Commons Daemon you can now have a custom executable name and icon! You can also get a custom Windows tray monitor with your own name and icon!

I now have my service running with my own name and icon (prunsrv.exe), and the system tray monitor (prunmgr.exe) also has my own custom name and icon!

  1. Download the Apache Commons Daemon binaries (you will need prunsrv.exe and prunmgr.exe).
  2. Rename them to be MyServiceName.exe and MyServiceNamew.exe respectively.
  3. Download WinRun4J and use the RCEDIT.exe program that comes with it to modify the Apache executable to embed your own custom icon like this:

  4. Now install your Windows service like this (see documentation for more details and options):

  5. Now you have a Windows service of your Jar that will run with your own icon and name! You can also launch the monitor file and it will run in the system tray with your own icon and name.


A simple way is the NSSM Wrapper Wrapper (see my blog entry).

Power off your ATI Radeon x1950 device. Disconnect the device from your computer. Reconnect the device and power it on. Double click the driver download to extract it. If a language option is given, select your language. Follow the directions on the installation program screen. Reboot your computer. Ati radeon x1950 windows 10. Sapphire Radeon X1950 Pro may sometimes be at fault for other drivers ceasing to function These are the driver scans of 2 of our recent wiki members.Scans were performed on computers suffering from Sapphire Radeon X1950 Pro disfunctions. May 18, 2016  I installed the ati driver and catalyst for Ati x1950 GT in windows 10 by downloading the catalyst driver from their site ( the vista 32-64 bit pack) and run it in compatibility mode for windows vista sp2. It worked just fine. No need to use other software or to disable your windows. Description: ATI Catalyst 9.­7 for Windows Vista,­ Windows 7 32-bit Display Driver ATI WDM Integrated Driver Catalyst Control Center (English Language Only) Download ATI Radeon X1950 Catalyst Software Suite v.9.7. Power off your Radeon X1950 Pro device. Disconnect the device from your computer. Reconnect the device and power it on. Double click the driver download to extract it. If a language option is given, select your language. Follow the directions on the installation program screen. Reboot your computer.


One more option is WinRun4J. This is a configurable java launcher that doubles as a windows service host (both 32 and 64 bit versions). It is open source and there are no restrictions on its use.

(full disclosure: I work on this project).


Yet another answer is Yet Another Java Service Wrapper, this seems like a good alternative to Java Service Wrapper as has better licensing. It is also intended to be easy to move from JSW to YAJSW. Certainly for me, brand new to windows servers and trying to get a Java app running as a service, it was very easy to use.

Some others I found, but didn't end up using:

  • Java Service Launcher I didn't use this because it looked more complicated to get working than YAJSW. I don't think this is a wrapper.
  • JSmooth Creating Window's services isn't its primary goal, but can be done. I didn't use this because there's been no activity since 2007.

I think the Java Service Wrapper works well. Note that there are three ways to integrate your application. It sounds like option 1 will work best for you given that you don't want to change the code. The configuration file can get a little crazy, but just remember that (for option 1) the program you're starting and for which you'll be specifying arguments, is their helper program, which will then start your program. They have an example configuration file for this.

Ed ThomasEd Thomas
7781 gold badge9 silver badges20 bronze badges

If you use Gradle Build Tool you can try my windows-service-plugin, which facilitates using of Apache Commons Daemon Procrun.

To create a java windows service application with the plugin you need to go through several simple steps.

  1. Create a main service class with the appropriate method.

  2. Include the plugin into your build.gradle file.

    The same script snippet for new, incubating, plugin mechanism introduced in Gradle 2.1:

  3. Configure the plugin.

  4. Run createWindowsService gradle task to create a windows service distribution.

That's all you need to do to create a simple windows service. The plugin will automatically download Apache Commons Daemon Procrun binaries, extract this binaries to the service distribution directory and create batch files for installation/uninstallation of the service.

In ${project.buildDir}/windows-service directory you will find service executables, batch scripts for installation/uninstallation of the service and all runtime libraries. To install the service run <project-name>-install.bat and if you want to uninstall the service run <project-name>-uninstall.bat.To start and stop the service use <project-name>w.exe executable.

Note that the method handling service start should create and start a separate thread to carry out the processing, and then return. The main method is called from different threads when you start and stop the service.

For more information, please read about the plugin and Apache Commons Daemon Procrun.


JavaService is LGPL. It is very easy and stable. Highly recommended.


With Java 8 we can handle this scenario without any external tools. javapackager tool coming with java 8 provides an option to create self contained application bundles:

-native typeGenerate self-contained application bundles (if possible). Use the -B option to provide arguments to the bundlers being used. If type is specified, then only a bundle of this type is created. If no type is specified, all is used.

Hunterbad 2019-01-06 3 points. I have a problem when i lunch engine this message pops 'NLE0007: You must specify a game name in the command line. For example, Creatures 3 or Creatures Adventures For soak tests, specify -autokill before the game name to kill agents which generate run time errors. Sun Jan 06 17: - M - 1.162' ↑ ↓. https://ninworldof.netlify.app/creatures-3-full-game-download.html. Mar 15, 2017  Creatures 3 Overview. Creatures 3 Free Download for PC is the third game in the Creatures a-life game series made by Creature Labs. In this installment, the Shee have left Albia in a spaceship, the Shee Ark, to search for a more spherical world. While Creatures 3 may appeal to many science fiction buffs, it is not without its problems. I found myself frustrated trying to play the game on my own prior to reading the manual, so, even if you are familiar with Creatures and Creatures 2 don't expect to jump right in. Gameplay can even be difficult to understand if you try to read the manual as you go along.

Without ZTE drivers, firmware flashing tools will not be able to detect the device and start the firmware flashing process.These ZTE Drivers are suitable for all ZTE series of devices which includes - Blade, Axon, Nubia, Max, Tempo, Maven, Grand, and Avid, etc. Zte drivers for pc free. Description:ZTE Drivers are essential for ZTE Android Smartphones and Tablets. These ZTE USB Drivers helps in resolving connection issues between a ZTE device and Windows 10/7/8/8.1 PC.The ZTE Phone Drivers address all the USB connection issues, be it transferring files between ZTE handset and PC, or debugging over.ZTE USB Drivers enables support for firmware flashing on a ZTE device.

The following values are valid for type:

In case of windows refer the following doc we can create msi or exe as needed.


Use 'winsw' which was written for Glassfish v3 but works well with Java programs in general.

Require .NET runtime installed.


I've used JavaService before with good success. It hasn't been updated in a couple of years, but was pretty rock solid back when I used it.

Jason

I didn't like the licensing for the Java Service Wrapper. I went with ActiveState Perl to write a service that does the work.

I thought about writing a service in C#, but my time constraints were too tight.

Hugh BuchananHugh Buchanan

I always just use sc.exe (see http://support.microsoft.com/kb/251192). It should be installed on XP from SP1, and if it's not in your flavor of Vista, you can download load it with the Vista resource kit.

I haven't done anything too complicated with Java, but using either a fully qualified command line argument (x:java.exe ..) or creating a script with Ant to include depencies and set parameters works fine for me.

KevinKevin

A pretty good comparison of different solutions is available at :http://yajsw.sourceforge.net/#mozTocId284533

Personally like launch4j


it's simple as you have to put shortcut in

Pi kappa alpha clothes. Pi Kappa Alpha (Pike) Apparel & Gifts - Lettered sweatshirts, printed tees and other Campus Classics exclusive merchandise for you to show your pride! Shop Pi Kappa Alpha apparel with Something Greek. Order Phi Kappa Alpha shirts and gear straight from the site, or have custom printed Pi Kappa Alpha shirts, flags & clothing for your event! Our Pi Kappa Alpha clothing designs incorporate the fraternity's official colors and Greek letters for easy recognition. We also carry decor items like a large Pike flag for outside of the chapter house or a Pi Kappa Alpha crest to hang on the wall. Looking for Pi Kappa Alpha rush shirts or a Pike long-sleeve shirt?

Windows 7C:usersAll UsersStart MenuProgramsStartup(Admin) or User home directory(%userProfile%)

Windows 10 :In Run shell:startup

in it's property -> shortcut -> target - >java.exe -jar D:.runJar.jar

NOTE: This will run only after you login

With Admin Right

sc create serviceName binpath= 'java.exe -jar D:.runJar.jar' Will create windows service

Java Wrapper Service

if you get timeout use cmd /c D:JAVA7~1jdk1.7.0_51binjava.exe -jar d:jenkinsjenkins.war but even with this you'll get timeout but in background java.exe will be started. Check in task manager

NOTE: This will run at windows logon start-up(before sign-in, Based on service 'Startup Type')


Another good option is FireDaemon. It's used by some big shops like NASA, IBM, etc; see their web site for a full list.

Andrew Swan

Java Service Wrapper Tutorial Windows

Java Service Wrapper TutorialAndrew Swan
9,04117 gold badges63 silver badges96 bronze badges

I am currently requiring this to run an Eclipse-based application but I need to set some variables first that is local to that application. sc.exe will only allow executables but not scripts so I turned to autoexnt.exe which is part of the Windows 2003 resource kit. It restricts the service to a single batch file but I only need one batch script to be converted into a service.

ciao!

ramfree17

Exe4j is a very good option although it is not free. Check it out at Exe4j In the wizard to create the .exe file, you are give the option to create a service.


Java Service Wrapper Tutorial

Not the answer you're looking for? Browse other questions tagged javawindows-services or ask your own question.