How to create a windows service from java app

前端 未结 19 1967
既然无缘
既然无缘 2020-11-22 04:09

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 neve

相关标签:
19条回答
  • 2020-11-22 05:06

    I've had some luck with the Java Service Wrapper

    0 讨论(0)
  • 2020-11-22 05:08

    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:

      > RCEDIT.exe /I MyServiceName.exe customIcon.ico
      > RCEDIT.exe /I MyServiceNamew.exe customTrayIcon.ico
      
    4. Now install your Windows service like this (see documentation for more details and options):

      > MyServiceName.exe //IS//MyServiceName \
        --Install="C:\path-to\MyServiceName.exe" \
        --Jvm=auto --Startup=auto --StartMode=jvm \
        --Classpath="C:\path-to\MyJarWithClassWithMainMethod.jar" \
        --StartClass=com.mydomain.MyClassWithMainMethod
      
    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.

    0 讨论(0)
  • 2020-11-22 05:12

    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!

    0 讨论(0)
  • 2020-11-22 05:14

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

    Personally like launch4j

    0 讨论(0)
  • 2020-11-22 05:14

    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.

    0 讨论(0)
  • 2020-11-22 05:15

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

    0 讨论(0)
提交回复
热议问题