0

I wrote a simple jersey webservice ( servlet based WAR ) to be OSGIfied and deployed into karaf . The application was coded using eclipse and as a maven web project, designed to be deployed as a WAR. Compiles & installs correctly and the war is generated without any errors. File contents below :-

Please do not log this as a duplicate to other similar questions because i checked those out and tried to apply some of the solutions given there as well ( unsuccessfully)

POM.XML

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ione</groupId>
<artifactId>karaftest</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>karaftest Maven Webapp</name>
<url>http://maven.apache.org</url>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
        <scope>provided</scope>
    </dependency>


    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" -->
        <artifactId>jersey-container-servlet</artifactId>
        <version>2.22.1</version>
        <scope>compile</scope>
    </dependency>
</dependencies>
<build>
    <finalName>karaftest</finalName>
    <plugins>

        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <executions>
                <execution>
                    <id>bundle-manifest</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>manifest</goal>
                    </goals>
                    <configuration>
                        <instructions>
                            <Bundle-SymbolicName>karaftest</Bundle-SymbolicName>
                            <Export-Package/>
                            <Import-Package/>
                            <Bundle-ClassPath>.,WEB-INF/classes</Bundle-ClassPath>
                            <Embed-Directory>WEB-INF/lib</Embed-Directory>
                            <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
                            <Embed-Transitive>true</Embed-Transitive>
                            <Web-ContextPath>karaftest</Web-ContextPath>
                            <Webapp-Context>karaftest</Webapp-Context>
                        </instructions>
                    </configuration>
                </execution>
            </executions>
            <configuration>
                <supportedProjectTypes>
                    <supportedProjectType>jar</supportedProjectType>
                    <supportedProjectType>bundle</supportedProjectType>
                    <supportedProjectType>war</supportedProjectType>
                </supportedProjectTypes>
                <instructions>
                    <!-- ... etc ... -->
                </instructions>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>



        <!-- Karaf stuff OSGIfy the WAR -->

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <archive>
                    <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                </archive>
            </configuration>
        </plugin>






        <!-- OSGIfication -->

    </plugins>
</build>

As you can see, i have only two dependencies declared ( out of which log4j is under provided scope )

The generated MANIFEST.MF

    Manifest-Version: 1.0
Bnd-LastModified: 1455060085036
Build-Jdk: 1.8.0_45
Built-By: nish
Bundle-ClassPath: .,WEB-INF/classes,WEB-INF/lib/jersey-container-servlet
 -2.22.1.jar,WEB-INF/lib/jersey-container-servlet-core-2.22.1.jar,WEB-IN
 F/lib/javax.inject-2.4.0-b31.jar,WEB-INF/lib/jersey-common-2.22.1.jar,W
 EB-INF/lib/javax.annotation-api-1.2.jar,WEB-INF/lib/jersey-guava-2.22.1
 .jar,WEB-INF/lib/hk2-api-2.4.0-b31.jar,WEB-INF/lib/hk2-utils-2.4.0-b31.
 jar,WEB-INF/lib/aopalliance-repackaged-2.4.0-b31.jar,WEB-INF/lib/hk2-lo
 cator-2.4.0-b31.jar,WEB-INF/lib/javassist-3.18.1-GA.jar,WEB-INF/lib/osg
 i-resource-locator-1.0.1.jar,WEB-INF/lib/jersey-server-2.22.1.jar,WEB-I
 NF/lib/jersey-client-2.22.1.jar,WEB-INF/lib/jersey-media-jaxb-2.22.1.ja
 r,WEB-INF/lib/validation-api-1.1.0.Final.jar,WEB-INF/lib/javax.ws.rs-ap
 i-2.0.1.jar
Bundle-ManifestVersion: 2
Bundle-Name: karaftest Maven Webapp
Bundle-SymbolicName: karaftest
Bundle-Version: 0.0.1.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Embed-Dependency: *;scope=compile|runtime
Embed-Directory: WEB-INF/lib
Embed-Transitive: true
Embedded-Artifacts: WEB-INF/lib/jersey-container-servlet-2.22.1.jar;g="o
 rg.glassfish.jersey.containers";a="jersey-container-servlet";v="2.22.1"
 ,WEB-INF/lib/jersey-container-servlet-core-2.22.1.jar;g="org.glassfish.
 jersey.containers";a="jersey-container-servlet-core";v="2.22.1",WEB-INF
 /lib/javax.inject-2.4.0-b31.jar;g="org.glassfish.hk2.external";a="javax
 .inject";v="2.4.0-b31",WEB-INF/lib/jersey-common-2.22.1.jar;g="org.glas
 sfish.jersey.core";a="jersey-common";v="2.22.1",WEB-INF/lib/javax.annot
 ation-api-1.2.jar;g="javax.annotation";a="javax.annotation-api";v="1.2"
 ,WEB-INF/lib/jersey-guava-2.22.1.jar;g="org.glassfish.jersey.bundles.re
 packaged";a="jersey-guava";v="2.22.1",WEB-INF/lib/hk2-api-2.4.0-b31.jar
 ;g="org.glassfish.hk2";a="hk2-api";v="2.4.0-b31",WEB-INF/lib/hk2-utils-
 2.4.0-b31.jar;g="org.glassfish.hk2";a="hk2-utils";v="2.4.0-b31",WEB-INF
 /lib/aopalliance-repackaged-2.4.0-b31.jar;g="org.glassfish.hk2.external
 ";a="aopalliance-repackaged";v="2.4.0-b31",WEB-INF/lib/hk2-locator-2.4.
 0-b31.jar;g="org.glassfish.hk2";a="hk2-locator";v="2.4.0-b31",WEB-INF/l
 ib/javassist-3.18.1-GA.jar;g="org.javassist";a="javassist";v="3.18.1-GA
 ",WEB-INF/lib/osgi-resource-locator-1.0.1.jar;g="org.glassfish.hk2";a="
 osgi-resource-locator";v="1.0.1",WEB-INF/lib/jersey-server-2.22.1.jar;g
 ="org.glassfish.jersey.core";a="jersey-server";v="2.22.1",WEB-INF/lib/j
 ersey-client-2.22.1.jar;g="org.glassfish.jersey.core";a="jersey-client"
 ;v="2.22.1",WEB-INF/lib/jersey-media-jaxb-2.22.1.jar;g="org.glassfish.j
 ersey.media";a="jersey-media-jaxb";v="2.22.1",WEB-INF/lib/validation-ap
 i-1.1.0.Final.jar;g="javax.validation";a="validation-api";v="1.1.0.Fina
 l",WEB-INF/lib/javax.ws.rs-api-2.0.1.jar;g="javax.ws.rs";a="javax.ws.rs
 -api";v="2.0.1"
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Tool: Bnd-3.0.0.201509101326
Web-ContextPath: karaftest
Webapp-Context: karaftest

I copied the generated WAR to karaf/deploy folder as per the instructions and ran karaf.bar server. It kept throwing the error below

karaf.bat: Ignoring predefined value for KARAF_HOME
ERROR: Bundle karaftest [139] Error starting file:/C:/Essentials/iONE/apache-kar
af-3.0.3/apache-karaf-3.0.3/deploy/karaftest.war (org.osgi.framework.BundleExcep
tion: Unresolved constraint in bundle karaftest [139]: Unable to resolve 139.0:
missing requirement [139.0] osgi.wiring.package; (osgi.wiring.package=com.sun.jd
i))
org.osgi.framework.BundleException: Unresolved constraint in bundle karaftest [1
39]: Unable to resolve 139.0: missing requirement [139.0] osgi.wiring.package; (
osgi.wiring.package=com.sun.jdi)
        at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:397
4)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2037)
        at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1291)

        at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStart
LevelImpl.java:304)
        at java.lang.Thread.run(Thread.java:745)

I don't know where it is trying to resolve com.sun.jdi. I understand that it is a package specific to proprietary sun classes. Things that i tried to resolve this issue and was unsuccessful

  1. Exclude this specific package via in maven bundle plugin using '!'
  2. Export this package so that it is available for the container using as mentioned in comment https://stackoverflow.com/a/23343263/1719473

I am brand new to OSGI universe ( like a day old ) so i am not really sure why is it so hard for it to deploy a simple WAR. Also, i do not know where it is picking up the info from my app WAR related to com.sun.jdi. I suspect if it is a transitive dependent jar to any of the jars resolved as part of jersey.

Any help is greatly appreciated ( with a beer if you are in bay area ) . Thanks

UPDATE

Updated MANIFEST.MF by changing POM.XML to import-packages . Still getting the same exception while deploying to karaf as WAR. It is visible in manifest.mf that com.sun.jdi is getting imported.

Update MANIFEST.MF

Manifest-Version: 1.0
Bnd-LastModified: 1455065767920
Build-Jdk: 1.8.0_45
Built-By: nish
Bundle-ClassPath: .,WEB-INF/classes,WEB-INF/lib/jersey-container-servlet
 -2.22.1.jar,WEB-INF/lib/jersey-container-servlet-core-2.22.1.jar,WEB-IN
 F/lib/javax.inject-2.4.0-b31.jar,WEB-INF/lib/jersey-common-2.22.1.jar,W
 EB-INF/lib/javax.annotation-api-1.2.jar,WEB-INF/lib/jersey-guava-2.22.1
 .jar,WEB-INF/lib/hk2-api-2.4.0-b31.jar,WEB-INF/lib/hk2-utils-2.4.0-b31.
 jar,WEB-INF/lib/aopalliance-repackaged-2.4.0-b31.jar,WEB-INF/lib/hk2-lo
 cator-2.4.0-b31.jar,WEB-INF/lib/javassist-3.18.1-GA.jar,WEB-INF/lib/osg
 i-resource-locator-1.0.1.jar,WEB-INF/lib/jersey-server-2.22.1.jar,WEB-I
 NF/lib/jersey-client-2.22.1.jar,WEB-INF/lib/jersey-media-jaxb-2.22.1.ja
 r,WEB-INF/lib/validation-api-1.1.0.Final.jar,WEB-INF/lib/javax.ws.rs-ap
 i-2.0.1.jar
Bundle-ManifestVersion: 2
Bundle-Name: karaftest Maven Webapp
Bundle-SymbolicName: karaftest
Bundle-Version: 0.0.1.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Embed-Dependency: *;scope=compile|runtime
Embed-Directory: WEB-INF/lib
Embed-Transitive: true
Embedded-Artifacts: WEB-INF/lib/jersey-container-servlet-2.22.1.jar;g="o
 rg.glassfish.jersey.containers";a="jersey-container-servlet";v="2.22.1"
 ,WEB-INF/lib/jersey-container-servlet-core-2.22.1.jar;g="org.glassfish.
 jersey.containers";a="jersey-container-servlet-core";v="2.22.1",WEB-INF
 /lib/javax.inject-2.4.0-b31.jar;g="org.glassfish.hk2.external";a="javax
 .inject";v="2.4.0-b31",WEB-INF/lib/jersey-common-2.22.1.jar;g="org.glas
 sfish.jersey.core";a="jersey-common";v="2.22.1",WEB-INF/lib/javax.annot
 ation-api-1.2.jar;g="javax.annotation";a="javax.annotation-api";v="1.2"
 ,WEB-INF/lib/jersey-guava-2.22.1.jar;g="org.glassfish.jersey.bundles.re
 packaged";a="jersey-guava";v="2.22.1",WEB-INF/lib/hk2-api-2.4.0-b31.jar
 ;g="org.glassfish.hk2";a="hk2-api";v="2.4.0-b31",WEB-INF/lib/hk2-utils-
 2.4.0-b31.jar;g="org.glassfish.hk2";a="hk2-utils";v="2.4.0-b31",WEB-INF
 /lib/aopalliance-repackaged-2.4.0-b31.jar;g="org.glassfish.hk2.external
 ";a="aopalliance-repackaged";v="2.4.0-b31",WEB-INF/lib/hk2-locator-2.4.
 0-b31.jar;g="org.glassfish.hk2";a="hk2-locator";v="2.4.0-b31",WEB-INF/l
 ib/javassist-3.18.1-GA.jar;g="org.javassist";a="javassist";v="3.18.1-GA
 ",WEB-INF/lib/osgi-resource-locator-1.0.1.jar;g="org.glassfish.hk2";a="
 osgi-resource-locator";v="1.0.1",WEB-INF/lib/jersey-server-2.22.1.jar;g
 ="org.glassfish.jersey.core";a="jersey-server";v="2.22.1",WEB-INF/lib/j
 ersey-client-2.22.1.jar;g="org.glassfish.jersey.core";a="jersey-client"
 ;v="2.22.1",WEB-INF/lib/jersey-media-jaxb-2.22.1.jar;g="org.glassfish.j
 ersey.media";a="jersey-media-jaxb";v="2.22.1",WEB-INF/lib/validation-ap
 i-1.1.0.Final.jar;g="javax.validation";a="validation-api";v="1.1.0.Fina
 l",WEB-INF/lib/javax.ws.rs-api-2.0.1.jar;g="javax.ws.rs";a="javax.ws.rs
 -api";v="2.0.1"
Import-Package: com.sun.jdi,com.sun.jdi.connect,com.sun.jdi.event,com.su
 n.jdi.request,javax.activation,javax.imageio,javax.imageio.spi,javax.im
 ageio.stream,javax.jws,javax.management,javax.naming,javax.net.ssl,java
 x.persistence,javax.servlet,javax.servlet.annotation,javax.servlet.http
 ,javax.xml.bind,javax.xml.bind.annotation,javax.xml.bind.annotation.ada
 pters,javax.xml.datatype,javax.xml.namespace,javax.xml.parsers,javax.xm
 l.stream,javax.xml.transform,javax.xml.transform.dom,javax.xml.transfor
 m.sax,javax.xml.transform.stream,javax.xml.validation,javax.xml.ws,jers
 ey.repackaged.com.google.common.cache.LocalCache.jersey.repackaged.com.
 google.common.cache,jersey.repackaged.com.google.common.cache.LocalCach
 e.jersey.repackaged.com.google.common.cache.LocalCache$jersey.repackage
 d.com.google.common.cache,jersey.repackaged.com.google.common.collect.A
 bstractMapBasedMultimap.jersey.repackaged.com.google.common.collect,jer
 sey.repackaged.com.google.common.collect.AbstractMapBasedMultimap.jerse
 y.repackaged.com.google.common.collect.AbstractMapBasedMultimap$Wrapped
 Collection.jersey.repackaged.com.google.common.collect,jersey.repackage
 d.com.google.common.collect.AbstractMultimap.jersey.repackaged.com.goog
 le.common.collect,jersey.repackaged.com.google.common.collect.FilteredK
 eyMultimap.jersey.repackaged.com.google.common.collect,jersey.repackage
 d.com.google.common.collect.ImmutableMultimap.jersey.repackaged.com.goo
 gle.common.collect,jersey.repackaged.com.google.common.collect.MapMaker
 InternalMap.jersey.repackaged.com.google.common.collect,jersey.repackag
 ed.com.google.common.collect.MapMakerInternalMap.jersey.repackaged.com.
 google.common.collect.MapMakerInternalMap$jersey.repackaged.com.google.
 common.collect,jersey.repackaged.com.google.common.collect.Maps$Filtere
 dEntryMap.jersey.repackaged.com.google.common.collect,jersey.repackaged
 .com.google.common.collect.StandardTable.jersey.repackaged.com.google.c
 ommon.collect,org.apache.log4j;version="[1.2,2)",org.osgi.framework,org
 .w3c.dom,org.xml.sax,org.xml.sax.helpers,sun.misc
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Tool: Bnd-3.0.0.201509101326
Web-ContextPath: karaftest
Webapp-Context: karaftest
Community
  • 1
  • 1
NishM
  • 1,706
  • 2
  • 15
  • 26
  • I am not importing packages. If you look at the pom.xml, you can see the empty element . Adding it does not do any good either since i am getting the same exception in karaf console. – NishM Feb 10 '16 at 00:36
  • The error message cannot come from the bundle you have listed... your bundle has no imported packages (because for some reason you have turned off all of the imports... bad idea!). But the error message says that one of the imports cannot be resolved. So perhaps this is from an earlier version of your bundle? – Neil Bartlett Feb 10 '16 at 00:38
  • I turned off imports just to see if that was causing the problem. I even tried ignoring the import but nothing worked. I restarted karaf multiple times during the whole debugging so i think it would refresh the bundle each time. Moreover i manually copy the WAR from maven target to karaf/deploy each time i change it. – NishM Feb 10 '16 at 00:41
  • 1
    Turning off imports will certainly get rid of errors about unresolvable imports! But it will cause other errors such as `NoClassDefFoundError` because your bundle will no longer be able to load any of its dependencies. Unfortunately I can't comment on why the bundle you think is running is not actually the one that is running. – Neil Bartlett Feb 10 '16 at 00:45
  • Appreciate the inputs. This is a fresh karaf install and this WAR is my first experiment with karaf so i am sure that there are no other bundles involved. Inferring to what you confirmed, Could this issue be related to my karaf runtime and not the WAR i am deploying?. – NishM Feb 10 '16 at 00:48
  • When I said you will not be able to load dependencies, this would include packages that come from the JRE itself. So it doesn't really matter that you don't have any other bundles. It's difficult to say whether this bundle will work but it seems unlikely: it's very big and complex, it contains a hell of a lot of embedded libraries, which all bring their own dependencies and other baggage. – Neil Bartlett Feb 10 '16 at 00:53
  • Updated the post with manifest.mf after adding import-package. – NishM Feb 10 '16 at 01:01
  • Have you first tried to get accustomed to the way WAB(War+Manifest) works, and did you take a look at the samples or integration tests of the Pax-Web project? Cause there are a lot of samples that will get you going a lot faster. AFAIK we now even have a Jersey sample in there. – Achim Nierbeck Feb 10 '16 at 16:16
  • I am used to the way it works but i figured this should be simpler when you want to just deploy a WAR to Karaf. Well, I moved away from using it entirely not because i was not able to solve this but because of the overhead involved in deploying something as simple as a WAR to the container. Keeping this question open if someone wishes to give an answer to it someday. – NishM May 25 '16 at 22:12

0 Answers0