Karaf 3 Service Wrapper bug : Could not find or load main class org.apache.karaf.wrapper.internal.Main

Hi, There:

Summer goes by pretty quickly!  We have been tackling this Karaf issue for the past 2-3 weeks now. Finally I found a solution to it and I hope my solution can help you.

Basically we have an application running under JDK 7 and Karaf 3.04 smoothly. We would like to wrap the application under a Windows’ service. Karaf has service-wrapper which runs as:

feature:install service-wrapper
wrapper:install -n MyService -d “MyWindowService”
feature:uninstall service-wrapper

The above script in Karaf runs fine and creates these three files:  MyService-service.bat, MyService-service.exe, MyService-service.conf

According to Karaf instruction, under Windows command line:

MyService install  should install the Windows service and you should be able to start the Windows service.

But … we kept getting this error:

Error: Could not find or load main class org.apache.karaf.wrapper.internal.Main

It actually points to a missing Class file. It turns out there is some bug in Karaf 3’s Service-Wrapper. When it creates the MyService-service.conf file, it misses one CLASSPATH line as below Classpath line 3.

wrapper.java.mainclass=org.apache.karaf.wrapper.internal.Main
wrapper.java.classpath.1=%KARAF_HOME%/lib/karaf-wrapper.jar
wrapper.java.classpath.2=%KARAF_HOME%/lib/karaf.jar
wrapper.java.classpath.3=%KARAF_HOME%/lib/karaf-wrapper-core-3.0.4.jar  
wrapper.java.classpath.4=%KARAF_HOME%/lib/karaf-jaas-boot.jar
wrapper.java.classpath.5=%KARAF_HOME%/lib/karaf-wrapper-main.jar
wrapper.java.classpath.6=%KARAF_HOME%/lib/karaf-org.osgi.core.jar

After manually download the wrapper-core jar file from maven (I modified the jar file name after download, an unnecessary step).

<dependency>
<groupId>org.apache.karaf.wrapper</groupId>
<artifactId>org.apache.karaf.wrapper.core</artifactId>
<version>3.0.4</version>
</dependency>

With the 3rd Classpath line in the conf file, and the downloaded jar file in Karaf’s lib folder, the windows service runs perfectly as we expected!

Cheers!

Be well and do quality coding!

-Tony