How to create a windows service from java app

前端 未结 19 1964
既然无缘
既然无缘 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: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.

提交回复
热议问题