0

I have the following error when running a jar wrapped by WinRun4J:

[info] Module Name: C:\Users\User\Documents\NetBeansProjects\NETBEANS 6.9.1\Desktop_apps\Test2\src\com\service\wrapper\ServiceWrapper.exe
[info] Module INI: C:\Users\User\Documents\NetBeansProjects\NETBEANS 6.9.1\Desktop_apps\Test2\src\com\service\wrapper\ServiceWrapper.ini
[info] Module Dir: C:\Users\User\Documents\NetBeansProjects\NETBEANS 6.9.1\Desktop_apps\Test2\src\com\service\wrapper\
[info] INI Dir: C:\Users\User\Documents\NetBeansProjects\NETBEANS 6.9.1\Desktop_apps\Test2\src\com\service\wrapper\
[info] Working directory set to: C:\Users\User\Documents\NetBeansProjects\NETBEANS 6.9.1\Desktop_apps\Test2\src\com\service\wrapper
[info] Configured vm.location:
[info] Found VM: C:\Program Files (x86)\Java\jre7\bin\client\jvm.dll
[info] Expanding Classpath: C:\Users\User\Documents\NetBeansProjects\NETBEANS 6.9.1\Desktop_apps\Test2\build\classes\
[info] Expanding Classpath: C:\Users\User\Documents\NetBeansProjects\NETBEANS 6.9.1\Desktop_apps\Test2\dist\lib\WinRun4J.jar
[info] Generated Classpath: C:\Users\User\Documents\NetBeansProjects\NETBEANS 6.9.1\Desktop_apps\Test2\dist\lib\WinRun4J.jar
[info] VM Args:
[info] vmarg.0=-Djava.class.path=C:\Users\User\Documents\NetBeansProjects\NETBEANS 
6.9.1\Desktop_apps\Test2\dist\lib\WinRun4J.jar
[info] Registering natives for Native class
[info] Registering natives for FFI class
 [err] Could not find service class
 [err] Failed to initialise service: 1
java.lang.NoClassDefFoundError: com/service/wrapper/ServiceWrapper/class
Caused by: java.lang.ClassNotFoundException: com.service.wrapper.ServiceWrapper.
class
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)

This is the service.ini I wrote for this wrapper ...

service.class=com.service.wrapper.ServiceWrapper
service.id=Service_Simulation
service.name=Windows_Java_Wrapped_Service
service.description=This is an Example for Java Service
service.startup="boot"
main.class=com.service.wrapper.ServiceWrapper
classpath.1=C:\Users\User\Documents\NetBeansProjects\NETBEANS 6.9.1\Desktop_apps\Test2\build\classes\
classpath.2=C:\Users\User\Documents\NetBeansProjects\NETBEANS 6.9.1\Desktop_apps\Test2\dist\lib\WinRun4J.jar

What did I miss?

Matthieu
  • 2,736
  • 4
  • 57
  • 87
LasithaMD
  • 115
  • 2
  • 11

1 Answers1

0

I believe you are using two incompatible parameters in your service.ini. You must introduce either service.class or main.class, but not both.

If you want your .exe to be executed always as a service, you must use service.class and register it in the Windows Service Manager, like so:

executable.exe --WinRun4J:RegisterService

If you want it to be a normal application, you must use main.class and call it normally.

If you want to execute it in both ways, you have to fall back to some roundabout like the one here. CopyPasting from the link:

I have the same requirement, for what will be around 10 or so services. Each must also be available to support people for command line execution, passing optional parameters for a "single run" mode of operation.

I have simply created a pair of ini files for each copy of the service executable that represents each service. Each service ini file is identical to it's command line partner apart from the head that follows, with the service/command line parts commented as appropriate:

working.directory=. 
service.class=com.xgs.cfs.services.ServiceControl 
service.id=service_id service.name=Windows Service Name 
service.description=Service Description
#command line app configuration
#main.class=com.xgs.cfs.services.ServiceControl
#console.title=process name
#singleinstance=process

The service is run from the Windows SCM and the command line launch uses the following command from a batch file, stored in a more user friendly location:

%deploymentroot%/svc_bin/service_name_svc.exe --WinRun4J:ExecuteINI %deploymentroot%/svc_bin/service_name_exe.ini

(%deploymentroot% is an environment variable used throughout the project to help manage paths.)

The above batch command is the key here, as it tells the winrun4j wrapper to use a different inin file to the default executable name. The service will pickup the default name (service_name_svc.ini) from the service binaries folder.

The class com.xgs.cfs.services.ServiceControl it written so that it has no dependencies on the service control callbacks for operation (i.e. it starts automatically, and all required normal shut down is accomplished via Java shut down hooks making the whole lot as ctrl-c safe as is possible.). You could simply change the startup class if required though I have found it unnecessary.

vguzmanp
  • 785
  • 1
  • 10
  • 31