2

I am trying to use Jersey through OSGi (Karaf, specifically). To do this, I downloaded this bundle jar from Maven and put it into my Karaf deploy directory. However, when I tried to start the bundle, it was unable to resolve any of it's dependancies. It also seemed to be looking for version 0.0.0 of each dependancy, which seems wrong.

What's the best way to get this bundle into my project? Do you I have to manually download all the dependancies, or can I use some existing OBR that has this bundle? Where would I find this?

Oleksi
  • 12,947
  • 4
  • 56
  • 80
  • 3
    I don't have an actual answer for you, but I can point out that looking for version 0.0.0 is not necessarily wrong. In OSGi that actually means "at least version 0.0.0" or in other words *any* version. It's actually pretty stupid of Jersey to do that, but that's not your fault! – Neil Bartlett Mar 23 '12 at 01:15
  • that has been fixed with version 1.13 onward – harschware May 17 '13 at 21:21

2 Answers2

8

I used Jersey with Karaf without problem using this dependencies instead of jersey-bundle:

<!-- Jersey -->
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-core</artifactId>
    <version>1.12</version>
</dependency>

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.12</version>
</dependency>

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-json</artifactId>
    <version>1.12</version>
</dependency>   

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>jsr311-api</artifactId>
    <version>1.1.1</version>
</dependency> 

I've tested now on the last Karaf Apache console and this worked for me:

$ bin/karaf
  Apache Karaf (2.2.5)

karaf@root> install mvn:com.sun.jersey/jersey-core/1.12
Bundle ID: 49
karaf@root> install mvn:com.sun.jersey/jersey-server/1.12
Bundle ID: 50
karaf@root> install mvn:javax.ws.rs/jsr311-api/1.1.1
Bundle ID: 51
karaf@root> install mvn:com.sun.jersey/jersey-json/1.12
Bundle ID: 52
karaf@root> install mvn:org.codehaus.jackson/jackson-core-asl/1.9.5
Bundle ID: 53
karaf@root> install mvn:org.codehaus.jackson/jackson-jaxrs/1.9.5
Bundle ID: 54
karaf@root> install mvn:org.codehaus.jackson/jackson-mapper-asl/1.9.5
Bundle ID: 55
karaf@root> install mvn:org.codehaus.jettison/jettison/1.1
Bundle ID: 56
karaf@root> start 49 50 51 52 53 54 55 56
karaf@root> list 
   ID   State         Blueprint      Level  Name
[  49] [Active     ] [            ] [   60] jersey-core (1.12)
[  50] [Active     ] [            ] [   60] jersey-server (1.12)
[  51] [Active     ] [            ] [   60] jsr311-api (1.1.1)
[  52] [Active     ] [            ] [   60] jersey-json (1.12)
[  53] [Active     ] [            ] [   60] Jackson JSON processor (1.9.5)
[  54] [Active     ] [            ] [   60] JAX-RS provider for JSON content type, using Jackson data binding (1.9.5)
[  55] [Active     ] [            ] [   60] Data mapper for Jackson JSON processor (1.9.5)
[  56] [Active     ] [            ] [   60] jettison (1.1)
jordeu
  • 6,711
  • 1
  • 19
  • 19
  • I'll have to wait a days to try this to make sure that it works, but I also have a dependency on com.sun.jersey.api.json, and I'm not sure what provides that. I recall it not being one of those three you listed. – Oleksi Mar 28 '12 at 18:12
  • Ok, then you need more things. I've added all jersey-json dependencies. – jordeu Mar 29 '12 at 06:32
  • So this satisfied Eclipse (after I added a missing one for jersey-servlet) and it seems that I at least have all the required bundles (thanks for that), however some of the bundles don't start because of uses conflicts. For example, when I start jersey-core, I get "could not be resolved. Reason: Package uses conflict: Import-Package: com.sun.jersey.api.uri; version="0.0.0"". However, this only seems to be a problem when I try it through eclipse. When I start things outside of eclipse, it seems to resolve correctly. Any advice? Thanks for your help. – Oleksi Mar 29 '12 at 20:14
  • I don't know. I'm always using Karaf with remote debug and dev:watch – jordeu Mar 29 '12 at 20:23
  • On further inspection, when I start my bundle outside of eclipse, I get the following: "Unable to resolve module myBundle because it is exposed to package 'javax.ws.rs' from javax.ws.rs.jsr311-api [52.0] and com.sun.jersey.jersey-core [65.0] via two dependency chains. ". I suspect this is related to why it won't work in eclipse either. – Oleksi Mar 29 '12 at 20:27
  • Check that you use the version 1.1.1 of javax.ws.rs on myBundle – jordeu Mar 29 '12 at 20:44
  • So I removed that dependancy from my pom file, and that fixed it outside of eclipse. Still broken in eclipse, but I can at least move on to other things. Thanks for your help. – Oleksi Mar 29 '12 at 21:01
1

I tried as well in Karaf (3.0.1) and it worked fined. I used Blueprint (in features.xml) and I added the following 3 JARs as bundles into my feature. I needed only for JSON conversion in a REST service.

<feature name="feature-name-test" version="${pom.version}">
  ....
  <bundle>mvn:org.codehaus.jackson/jackson-core-asl/${jackson.version}</bundle
  <bundle>mvn:org.codehaus.jackson/jackson-mapper-asl/${jackson.version}</bundle>
  <bundle>mvn:org.codehaus.jackson/jackson-jaxrs/${jackson.version}</bundle>
  ....
</feature>

where ${jackson.version} is a property which was defined in pom.xml (in my case 1.9.0). The same way works if you just install them from Karaf console.

stefan.itu
  • 41
  • 5