7

I'm trying to deploy Jersey 2.13 web services to Weblogic 12.1.1. This version of weblogic is compliant with JSR-311 JAX-RS 1.1 specification whereas Jersey 2.x provides implementation for JAX-RS 2.0

Oracle has an instruction on how to upgrade the version of Jersey JAX-RS RI : http://docs.oracle.com/cd/E24329_01/web.1211/e24983/version.htm

However even this doesn't help solving all of the deployment issues.

I'm packaging the application in EAR containing WAR. In order to override weblogic jars I've included added the following weblogic-application.xml file :

<?xml version="1.0" encoding="ISO-8859-1"?>
<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90">
  <prefer-application-packages>
    <!-- apis -->
    <package-name>javax.ws.rs.*</package-name>
    <!-- guava -->
    <package-name>com.google.common.*</package-name>
    <!-- jersey1 providers -->
    <package-name>com.sun.jersey.*</package-name>
    <!-- media providers -->
    <package-name>org.eclipse.persistence.jaxb.rs.*</package-name>
    <package-name>org.codehaus.jackson.jaxrs.*</package-name>
    <!-- wls -->
    <package-name>weblogic.jaxrs.api.client.*</package-name>
    <package-name>weblogic.jaxrs.internal.api.client.*</package-name>
    <package-name>weblogic.jaxrs.dispatch.*</package-name>
    <package-name>weblogic.jaxrs.monitoring.util.*</package-name>

   </prefer-application-packages>
</weblogic-application>

This configuration gives me a following error message on deployment :

Caused By: java.lang.NoSuchMethodError: org.glassfish.hk2.api.ServiceLocatorFactory.create(Ljava/lang/String;Lorg/glassfish/hk2/api/ServiceLocator;Lorg/glassfish/hk2/extension/ServiceLocatorGenerator;Lorg/glassfish/hk2/api/ServiceLocatorFactory$CreatePolicy;)Lorg/glassfish/hk2/api/ServiceLocator;

If I try to replace org.glassfish.hk2.* classes by adding it to prefer-application-packages I receive new errors and it's continuing forever...

Has anyone migrated Jersey to version 2.x on weblogic 12.1.1 or below?

Thanks!

andreybavt
  • 1,301
  • 4
  • 17
  • 32
  • Did you ever find a solution to this? I'm getting the same error, but it occurs randomly. Sometimes the libs are overridden, sometimes not. – retrodev Nov 10 '14 at 12:56
  • Hey, @retrodev, yes I'll post my weblogic-application.xml below as an answer. – andreybavt Nov 10 '14 at 20:09

4 Answers4

24

In the end it turned out that you actually have to replace more jars than Oracle suggests. Here's what my weblogic-application.xml looks like :

 <prefer-application-packages>
    <package-name>com.sun.jersey.*</package-name>
    <package-name>org.glassfish.jersey.*</package-name>
    <package-name>org.glassfish.hk2.*</package-name>
    <package-name>org.jvnet.hk2.*</package-name>
    <package-name>jersey.repackaged.org.objectweb.asm.*</package-name>

    <package-name>com.sun.research.ws.wadl.*</package-name>
    <package-name>com.sun.ws.rs.ext.*</package-name>

    <package-name>org.codehaus.jackson.*</package-name>
    <package-name>com.fasterxml.jackson.*</package-name>

    <package-name>org.codehaus.jettison.*</package-name>

    <package-name>javax.ws.rs.*</package-name>

    <package-name>org.objectweb.asm.*</package-name>

    <package-name>antlr.*</package-name>

  </prefer-application-packages>

Hope it helps.

andreybavt
  • 1,301
  • 4
  • 17
  • 32
11

For those who would like to use even newer version of Jersey (works with 2.15 up to 2.20, which is currently in a SNAPSHOT version), this is another version of weblogic.xml. Note that this set of package names is determined by single dependency to

<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
</dependency>

File weblogic.xml (includes also resources, which is not covered in AndreyBavt's answer and not even in the official doc):

<wls:container-descriptor>
    <wls:prefer-application-packages>
        <!-- jsr311 -->
        <wls:package-name>javax.ws.rs.*</wls:package-name>
        <!-- javassist -->
        <wls:package-name>javassist.*</wls:package-name>
        <!-- aop repackaged -->
        <wls:package-name>org.aopalliance.*</wls:package-name>

        <!-- jersey 2 -->
        <wls:package-name>jersey.repackaged.*</wls:package-name>
        <wls:package-name>org.glassfish.jersey.*</wls:package-name>
        <wls:package-name>com.sun.research.ws.wadl.*</wls:package-name>

        <!-- hk2 -->
        <wls:package-name>org.glassfish.hk2.*</wls:package-name>
        <wls:package-name>org.jvnet.hk2.*</wls:package-name>
        <wls:package-name>org.jvnet.tiger_types.*</wls:package-name>
    </wls:prefer-application-packages>

    <wls:prefer-application-resources>
        <wls:resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</wls:resource-name>
        <wls:resource-name>META-INF/services/javax.ws.rs.ext.RuntimeDelegate</wls:resource-name>

        <!-- jersey -->
        <wls:resource-name>META-INF/services/org.glassfish.jersey.*</wls:resource-name>
        <wls:resource-name>org.glassfish.jersey.*</wls:resource-name>
        <wls:resource-name>jersey.repackaged.*</wls:resource-name>

        <!-- hk2 -->
        <wls:resource-name>META-INF/services/org.glassfish.hk2.*</wls:resource-name>
    </wls:prefer-application-resources>
</wls:container-descriptor>

Tested with Weblogic 12.2.1

Stepan Vavra
  • 3,884
  • 5
  • 29
  • 40
  • Similar with the upper answer, the JEE annotations `@EJB` and `@Resource` do not work – George Aug 22 '15 at 16:39
  • I had equivalent problem with WLS 12.2.1.3 and Jersey 2.23.1. I've used wls-cat to determine prefer-application-packages, but I was not aware of prefer-application-resources requirement. It did the job. Tks for sharing. – Reginaldo Santos Nov 10 '17 at 20:09
6

I had the same problem when I upgraded my Jersey to 2.22.

The Weblogic 12.1.3 uses the 1.18 version of Jersey. To upgrade to another one, you can deploy the Jersey 2.x as a library on Weblogic and shared with your applications or config Weblogic to use Jersey from your application by weblogic.xml.

In my case I choose the second option:

weblogic.xml:

<prefer-application-packages>
    <package-name>javax.ws.rs.*</package-name>
    <package-name>com.sun.jersey.*</package-name>
    <package-name>org.glassfish.*</package-name>
    <package-name>org.jvnet.hk2.*</package-name>
    <package-name>jersey.repackaged.org.objectweb.asm.*</package-name>
</prefer-application-packages>
I. Medina
  • 115
  • 1
  • 6
1

I have created a simple maven project to produce the war file with the 2.19 jersey shared library for weblogic.
You can clone from here weblogic-jax-rs
After cloning run mvn package to produce the war and then deploy it to the server

As of weblogic 12.2.1 - there is jersey 2.21.1 bundled with it so no additional installations are required.

weblogic 12.2.1.1 comes with jersey 2.22.1

George
  • 7,206
  • 8
  • 33
  • 42
  • Hi George will this work on both 12.1.3 and 12.2.1 ? I am trying to find a config that will run on both – Astronaut Jun 27 '16 at 13:40
  • @Astronaut You don't need this for 12.2.1. It ships with jersey 2.21.1 out of the box. You don't have to do anything there. I will update the answer. – George Jun 27 '16 at 18:30
  • Hi George, yes but i want to have the same code base for both 12.1.3 and 12.2.1. Please see http://stackoverflow.com/questions/38052931/jersey-2-x-web-app-on-wl-12-2-1-and-12-3-1 – Astronaut Jun 28 '16 at 08:16
  • 1
    Hi @Astronaut, did you check the jar file? Is your problem solved yet? – George Jun 30 '16 at 11:37
  • Hi, unfortunatly i was not able to fix it. I do have the jar in the lib folder... but then it trows other eceptions – Astronaut Jun 30 '16 at 12:27
  • @Astronaut, Then perhaps other jars are missing too. Jersey has and uses a lot of modules depending on the application needs. If you can not upgrade all servers to 12.2.1 (which I recommend) then you should try to add all the jersey module dependencies listed here https://jersey.java.net/documentation/latest/modules-and-dependencies.html For example you can see the cdi1x transitive dependencies which should be present also: https://jersey.java.net/project-info/2.23.1/jersey/project/project/jersey-cdi1x/dependencies.html – George Jun 30 '16 at 16:10