24

I am trying to use Jersey 2.10 in Websphere 8 but it tries to reference the Application which is a implementation of JAX-RS 1.1 (default Wink) I get this below error even though I disabled to JAX-RS default by setting the IBM property.

Caused by: java.lang.NoSuchMethodError: javax/ws/rs/core/Application.getProperties()Ljava/util/Map; at org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:287) at org.glassfish.jersey.servlet.WebComponent.(WebComponent.java:311)

I read a post that says to make class loading policy to PARENT_LAST. Changing that option was disabled on WAS console, so I tried using the (Publishing settings for WAS - Run server with resources on Server) and my server got crashed.

Please advise. Thanks.

ᄂ ᄀ
  • 5,669
  • 6
  • 43
  • 57
jerry
  • 253
  • 1
  • 2
  • 6

1 Answers1

32

You need to do the following steps:

Disable built in JAX-RS via JVM property com.ibm.websphere.jaxrs.server.DisableIBMJAXRSEngine=true see description here.
You can set this property via web admin console in Servers > WebSphere Application Servers > yourServerName. Then in Server Infrastructure section Java and Process Management > Process definition > Java Virtual Machine > Custom properties.

Create isolated shared library with all JAX-RS 2.10 libraries, in console via Environment > Shared Libraries.

Isolated shared library is created via checking Use an isolated class loader for this shared library Class Loading option, when creating library.

Map this shared library to your application, either during installation or later on, via Applications > appName > Shared library references.

Restart application server. In the SystemOut.log you should see message initializing JAX-RS classes:

[7/12/14 16:10:36:470 CEST] 0000004a JerseyServlet I   Registering the Jersey servlet application, named javax.ws.rs.core.Application, with the following root resource and provider classes: [class jax.Hello, class org.glassfish.jersey.server.wadl.internal.WadlResource]
[7/12/14 16:10:36:688 CEST] 0000004a ApplicationHa I   Initiating Jersey application, version Jersey: 2.10.1 2014-06-30 13:53:32...

UPDATE

It appears that it is also possible to load the JAX-RS jars from within the WAR. You have to set this DisableIBMJAXRSEngine property and you need to change the class loading option in the module (not on EAR level) classloader to Classes loaded with local class loader first (parent last)

In the admin console:

Applications > WebSphere Enterprise Applications > {your.application} > Manage Modules > {your.module}

Change the Class loader order dropdown to: Classes loaded with local class loader first (parent last).

Thanks for dooffas for checking it, see JAX-RS 2.0 WebSphere 8.5 without isolated shared library

Community
  • 1
  • 1
Gas
  • 17,601
  • 4
  • 46
  • 93
  • The recommended setting worked and Jersey 2.5 is up and running. How does it work on network deployments? Does these shared libraries be on a physical location outside the deployed app? If so, it would be difficult. Please advise if there is any alternative. – jerry Jul 15 '14 at 13:25
  • Yes, you need to place shared library in the same location on all nodes that run servers running your application. Alternative - you could consider, whether you really need 2.x JAX-RS :). Java EE 6 requires 1.1, which is fully supported in WAS. If you use third party implementation and find any bugs in it, it wont be supported by IBM. The other alternative could be, to try to use lightweight WebSphere Liberty profile from 8.5.5, which by default doesn't have JAX-RS libs, so you could provide them in the application. I know that this is not what you were counting on. – Gas Jul 15 '14 at 19:32
  • 2
    Is it possible to turn the JAX-RS engine off through MANIFEST.MF file?It was possible to turn off the JAX-WS engine. I would like to use JAX-RS provided with application, without modifying the application server. – Jurica Krizanic Aug 28 '14 at 19:02
  • Unfortunately the only described in the documentation method for disabling JAX-RS is via server property. – Gas Aug 28 '14 at 20:05
  • So, this parameters is set in Application servers > server1 > Process definition > Java Virtual Machine > Custom properties? – Jurica Krizanic Aug 29 '14 at 07:02
  • @JuricaKrizanic Yes, you are correct. I updated the answer with full path in the console. – Gas Aug 29 '14 at 07:58
  • 1
    Thanks! Is it possible to set the parameter and avoid creating Shared libraries, but instead pack the JAX-RS 2.0 jars into the my application war? Managed to change the parameter, restart the WebSphere, and trying to load the JAX-RS from my application, but it fails with exception from the question. – Jurica Krizanic Aug 29 '14 at 08:05
  • Would like to avoid shared libraries (and liberty profile) if possible but not sure im fully understanding the implications of this statement from above "the only described in the documentation method for disabling JAX-RS is via server property". Does this mean that yes we can disable the websphere impl of Jax RS and package our own within the application war? – icyitscold Nov 20 '14 at 15:37
  • @icyitscold Unfortunately it is not possible. You have to define property and isolated shared library. Any reasons why you don't want to create shared library or cant use built in JAX-RS? It is just done once, and your war will be smaller, so it will deploy faster. – Gas Nov 20 '14 at 18:53
  • 1
    @Gas Thanks for your clarification! I guess I'll have to explore the shared library approach then. We distribute container agnostic software to customers who then have to deploy in their own environments. A shared library isnt something we've had to do before and each additional configuration/deployment step for our websphere customers means one more potential support headache for us - supporting jaxrs 1.1 on the other hand would require a rethink. – icyitscold Nov 21 '14 at 04:42
  • @icyitscold Each app server certified for Java EE 6 (like WebSphere, WebLogic or JBoss) already contains JAX-RS 1.1 implementation and Java EE 7 servers will include 2.0, so you will not need to include that. Only servlet containers don't provide it by default. You could check WebSphere Liberty Beta, which contains JAX-RS 2.0, maybe thats an option depending on your release date. – Gas Nov 21 '14 at 09:47
  • Saddly, won't worked for me... I don't know why I can't add shared libraries (have no scope items in dropdown box). And using class loading module option won't work too( throw this error: http://www.errbay.com/?r=IBM-WAS-08.5&c=CWNEN0070W). The only option was downlgrade to jersey 1.19. – ton Oct 23 '15 at 13:32
  • @Gas thanks for the detailed explanation. I was able to overcome the error Caused by: java.lang.NoSuchMethodError: javax/ws/rs/core/Application.getProperties()Ljava/util/Map. However, my Rest Service is still not getting invoked. I've created the Isolated shared library reference, and also added the JVM Property as suggested. When i'm trying to invoke the Service, the jersey container servlet is intercepting the request, however its returning with 404 Error. Ive tried adding Jerseys LoggingFilter for debugging purpose. Still not able to find the root cause, any help is appreciated. – Sandeep Salian Aug 25 '17 at 06:10
  • @SandeepSalian I assume you correctly see the `Initiating Jersey application` message, 404 usually means that you have problems in the URL, so double check that you have correct `/contextRoot/applicationPath/serviceParth`, as it looks like you may have incorrect `servicePath`. – Gas Aug 25 '17 at 11:09
  • @Gas Yes, I verified the URL. it was fine. However, I finally could get it working in Websphere 8.5.0.0. I placed all the Rest Service Classes in WEB-INF/classes folder, instead of placing the jar in WEB-INF/lib. After this change it worked fine. I'm not sure of the exact reason for this behavior. Without this change, even though Jersey Container Servlet is intercepting the request, it returns with 404 Error. – Sandeep Salian Aug 28 '17 at 12:18
  • Thank you, this works good with Jersey jax ri 2.31 and Websphere 8.5.5.17 – Gabriel Hernandez Aug 18 '20 at 01:35