Equinox as a Service
June 10, 2007
… “Bug 176928″
No doubt about it, Equinox has high potentials for server-side use. Therefore the question arises: what would be a convenient way to run Equinox applications as a service on Windows platforms (just like Tomcat does)?

On the one hand, we’ve got the Tanuki service wrapper as a weapon of choice to run java apps as a Windows Service or Unix Daemon. And on the other hand?
Pascal mentioned the FrameworkAdmin service as one way to launch Equinox. While this tool is nice as a framework independent runtime infrastructure, it seems over-complicated to me (as long as OSGi framework independence is not an issue). If I understand the Equinox implementation correctly, there is already a clue inside org.eclipse.equinox.launcher. We can launch Equinox by triggering org.eclipse.equinox.launcher.Main.main().
Let’s start with a common Equinox application directory structure:
myapp/
configuration/
features/
plugins/
eclipsec.exe
eclipse.ini
Whereas my plugins directory looks like..

Note: The org.eclipse.equinox.launcher bundle is new to Eclipse Equinox 3.3. Actually it is the former startup.jar, wich is a bundle now and moved to the plugins directory. However, for convenience, I use it as well together with 3.2. It can be downloaded as a separate bundle from one of the 3.3 Equinox download sites
So far, it should be possible to launch this configuration via eclipsec.exe or directly with java:
java -jar plugins/org.eclipse.equinox.launcher_1.0.0.v20070208a.jar
Once this works, we can take the next step and configure the Tanuki service wrapper.
According to the docs, I’ve copied the wrapper.exe, wrapper.conf and the lib folder from the wrapper for windows distribution into my application directory.
myapp/
configuration/
features/
plugins/
lib/
wrapper.jar
wrapper.dll
eclipsec.exe
eclipse.ini
wrapper.exe
wrapper.config
Now the wrapper.conf must be modified in order to install the service:
1) Setting the Main-Class
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
The simplest approach is to use the given WrapperSimpleApp (Method 1) and provide the class name we actually want to launch as a parameter.
wrapper.app.parameter.1=org.eclipse.equinox.launcher.Main
2) Specify the classpath
wrapper.java.classpath.1=./lib/wrapper.jar wrapper.java.classpath.2=./plugins/org.eclipse.equinox.launcher_1.0.0.200706082353.jar
These are the only two jar files needed, since Equinox is taking care of the classpath autonomously.
3) Path of the lib directory
wrapper.java.library.path.1=./lib
This is where the wrapper.dll is located.
4) Service Properties (self-explanatory)
wrapper.ntservice.name=MyEquinox wrapper.ntservice.displayname=My Equinox Server wrapper.ntservice.description=My Equinox Server
Finished. Now we can install the windows service by executing the wrapper.exe on the command line:
myapp> wrapper.exe -i wrapper | My Equinox Server installed.
PS: The wrapper.exe is looking for a file named wrapper.conf per default, so we don’t have to specify anything else. Voilà:

Just a note at the end: Even though the way described above is simple, it is not perfect. Stopping the service causes the framework simply exit by calling System.exit(0). Anyhow, it’s possible to cleanly stop (shutdown) the framework, but might necessitate to implement a WrapperStartStopApp helper class (see Method 2).
Resources:









