Using YAJSW to run a jar as a windows service

4.2k Views Asked by At

I've been looking at different articles, examples for hours and have successfully completely confused myself. I am trying to use YAJSW as a service wrapper and install my Executable JAR file as a windows service. I used to use Tanukisoft's community edition wrapper and it worked wonderfully, but the 64-bit Windows version isn't available in CE.

I suppose I have a few questions.

  1. In the old software, I didn't need to Implement WrapperListener. Is this necessary for YAJSW?
  2. If so, are there any good examples? I've seen a few, but my application doesn't return anything from the main class. It's main class is a constant running URL connection reading input from a REST API and spawning a thread to process the information received. It does have a shutdown hook for a clean exit.
  3. Is there an easy way to translate Tanukis' configuration (below) into YAJSW's keeping the same functionality?
    set.JAVA_HOME=C:/Program Files/Java/jre1.8.0_181
    set.APP_HOME=G:/ProgFolder
    wrapper.lang.folder=%APP_HOME%/lang
    wrapper.java.command=java

    wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp

    # Java Classpath (include wrapper.jar)  Add class path elements as
    #  needed starting from 1
    #wrapper.java.classpath.1=../lib/wrappertest.jar
    wrapper.java.classpath.1=%APP_HOME%/lib/wrapper.jar
    wrapper.java.classpath.2=%APP_HOME%/RESTReader.jar
    wrapper.java.classpath.3=%APP_HOME%/lib/javax.mail.jar
    wrapper.java.classpath.4=%APP_HOME%

    # Java Library Path (location of Wrapper.DLL or libwrapper.so)
    wrapper.java.library.path.1=%APP_HOME%/lib

    # Java Bits.  On applicable platforms, tells the JVM to run in 32 or 64-bit mode.
    wrapper.java.additional.auto_bits=TRUE

    # Java Additional Parameters
    wrapper.java.additional.1=-Dlog4j.configurationFile=file:/%APP_HOME%/conf/log4j2.xml
    wrapper.java.additional.2=-Dorg.tanukisoftware.wrapper.WrapperSimpleApp.waitForStartMain=FALSE

    # Application parameters.  Add parameters as needed starting from 1
    #wrapper.app.parameter.1=
    wrapper.app.parameter.1=com.my.org.RESTReader.EventReg

    wrapper.jvm_exit.timeout=120
    wrapper.shutdown.timeout=120

    # Name of the service
    wrapper.name=RESTReader

    # Display name of the service
    wrapper.displayname=REST Alarm Manager

    # Description of the service
    wrapper.description=REST Alarm Manager

    # Mode in which the service is installed.  AUTO_START, DELAY_START or DEMAND_START
    wrapper.ntservice.starttype=DELAY_START

    # Allow the service to interact with the desktop.
    wrapper.ntservice.interactive=false
1

There are 1 best solutions below

0
On

First Time Install (i.e. no existing service installed on host)

  1. build executable jar file for your app
  2. copy jar file to target windows machine / target directory
  3. copy yajsw.zip to target machine / target directory
  4. On target windows machine / target directory:
    1. Unzip contents of yajsw.zip. Once this is completed, the yajsw.zip file can be deleted.
    2. Open Windows command prompt in target machine / target directory and run: java -jar yourExecutableJar.jar
    3. Get Process ID for the java process that you just started using Windows Task Manager.
    4. Open new command window at target-dir\yajsw\yajsw-stable-majorversion.minorversion\bat.
    5. Run as admin genConfig [processId] where processID is the one you determined before
    6. Stop java process started previously
    7. Open wrapper.conf in target-dir\yajsw\yajsw-stable-majorversion.minorversion\conf
    8. Edit the fields in wrapper.conf: wrapper.ntservice.name=YourServiceName; wrapper.ntservice.displayname=YourServiceDisplayName;wrapper.ntservice.description=YourServiceDescription
    9. Save your changes and close wrapper.conf
    10. Run as admin installService in target-dir\yajsw\yajsw-stable-majorversion.minorversion\bat
    11. Run as admin startService in target-dir\yajsw\yajsw-stable-majorversion.minorversion\bat

Update Instructions

  1. Stop the service using Windows Task Manager or Services Manager
  2. In installed directory, delete the existing jar file for the project
  3. copy new jar file to installed directory
  4. Restart the service.