Java Service Wrapper Tutorial

Active6 years, 6 months ago

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 it took a bit. All versions of the Java Service Wrapper are available below. The latest release is considered stable. (Immediately after a new release, we will provide both latest and greatest, as well as stable release sections. The latest and greatest release is then promoted to stable after a period of time without any critical problems being reported.).

I have simply donwloaded JSW community edition, unwrapped into a directory:
c:servicetest
So here i have a bin, conf, lib and log subdirs, among others.From now on this will be (root).
I referenced the (root)/lib/wrapper.jar into my ide (netbeans) and create a very simple service (remember the class name is Main):

As you see, it basically does nothing but logging a message. But actually it neither starts.

I compiled the project (MyProject.jar), copied the jar into the (root) directory and modified the (root)/config/wrapper.conf adding:

and

Then i've installed the service in command line, with:

then i've started the service, either via services.msc control panel or via

In logs/wrapper.log i get:

UPDATE 1

Following Tanuki Software advice, i've set in my (root)/config/wrapper.conf (well, uncommented since it already was):

And now i get this:

But given my very simple implementation, i cannot guess what is going wrong.

AgostinoX
AgostinoXAgostinoX
3,74317 gold badges65 silver badges111 bronze badges

1 Answer

rather than extending WrapperSimpleApp, your main class should implement the org.tanukisoftware.wrapper.WrapperListener interface.

It was taking up too much space and who needs it, anyways?-Added Web Browser (also in Fun Stuff and in Startup Menu)Version 5.7 Update-Made Buttons Cooler.-Added Admin Menu for DragonFable. Since Load Class didn't work for DragonFable, just use the Admin Menu.-Fixed Bug for the Music. Mechquest walkthrough. (exits when you click on 'Screen Sizer')Version 4.7 Update:-Added Class Hack-Made Video Player At The Startup Screen.Version 5.0 Update:-Added Change Race Hack-Added Change Gender Hack-Added Change Name Hack-Added Go to Frame Hack-Added Freeze Enemy.-Removed 'Updates' part. (when you close the trainer music keeps going) When the trainer closes, it should stop the music automatically.

You can find a very detailed description about implementing the interface on our website:http://wrapper.tanukisoftware.com/doc/english/integrate-listener.html

Please let me know if you have any further questions about the implementation and/or the configuration properties in your conf file.

Another advise which comes in handy for me sometimes, is rather than running your application immediately as service, I find it easier to do the integration by running first as console application, because you can see the output directly on your console. Once everything seems working, I go ahead and install/run as service. To run as console application, you would run for example:

You can also turn on debug output for the Wrapper by setting

in your conf file.

Edit due to the comment:

if your application is actually as simple as you describe, then just write your application as normal Java application without any Wrapper API parts.

Java Service Wrapper Tutorial

You can use the WrapperSimpleApp to run your application out of the box with codeless integration into the Wrapper.

All you need to do is set the following properties in your conf file:

With this configuration, the Wrapper will be able to run your application as windows service.

UPDATE2

I'm not sure what your code exactly looks like, but it seems you are calling WrapperManager.stop() in your main class..

Following the initial example class, I have modified the class, so it is not using any Wrapper-API (which for an simple application is not necessary):

After compile and creating the jar, the necessary properties in the conf file are:

cheers,

NaytzyrhcNaytzyrhc

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

Active1 year, 10 months ago

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.


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).


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.

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.

Free john deere manuals pdf. Find great deals on eBay for john deere 260 manual. Shop with confidence. Skip to main content. John Deere Technical Manual 260, 270 Skid Steer Loader TM1780 (NOV03) English. John Deere 260 & 270 Skid Steer Technical Service Repair Manual - TM1780 See more like this. Aug 04, 2011  John Deere 240, 245, 260, 265, 285 & 320 Lawn Tractor Service Manual. The Service repair manual will give you complete step by step information on repair, servicing and preventative maintenance for your lawn tractor. The manual is highly detailed with photos and illustrations to help guide you through every repair and troubleshooting procedure. John Deere offers a range of technical and operator publications and training. Discover how to find, view, and purchase technical and service manuals and parts catalogs for your John Deere equipment. Find or View Operator Manuals Online. View Operator Manual Engine Maintenance Information; Educational Curriculum. We offer five. John Deere 260 Skid Steer Loader Service Manual John Deere 260 Skid Steer Loader Technical Manual TM1780 590 Pages in.pdf format 18.4 MB in.zip format for super fast downloads! This factory John Deere Service Manual Download will give you complete step-by-step information on repair, servicing, and preventative maintenance for your John Deere. JOHN DEERE 260 270 SKID STEER LOADER service manual & repair manual can easily help you with any repairs that you may need to do. Many people are scared to touch their machine because it seems difficult. This is only true when you do not have the resources.

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

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

Saboteur card game. With the help of Dwarf Cards, the players are assigned their role: either miner or saboteur. The roles are kept secret- they are only revealed at the end of the round. The Start Card and the three Goal Cards are placed onto the table, each seven cards away from the start and one card between each Goal Card. The Goal Cards are placed face-down. Saboteur is a mining-themed card game, designed by Frederic Moyersoen and published in 2004 by Z-Man Games. Players are assigned either a 'Miner' or a 'Saboteur' role,. Feb 26, 2019  Saboteur Mother Lode Bonus Pack Card Game with Saboteur, 2, & Secret Collectors’ Card—Amazon Exclusive $16.99. Customers also shopped for. Page 1 of 1 Start over Page 1 of 1. This shopping feature will continue to load items. In order to navigate out of this carousel please use your heading shortcut key to navigate to the next or previous. Buy AMIGO Games Saboteur Card Game: Card Games - Amazon.com FREE DELIVERY possible on eligible purchases.

With Admin Right

sc create serviceName binpath= 'java.exe -jar D:.runJar.jar' Will create windows 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')


Java Service Wrapper Spring Boot

Service

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

ExampleAndrew SwanAndrew 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!

Java Wrapper Classes Tutorial

ramfree17

Java Wrapper Method

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.


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