Java RestFull WebService: JAX-RS implementation with Jersey 2.3.1 libraries
Solution 1:
NoSuchMethodError
usually means you are having two different versions of the class on your classpath. As the javax.ws.rs.core.Application
class does have the getProperties()
method in its JAX-RS 2 version, but not in JAX-RS 1.x, I would guess that somehow you are combining the old 1.x Jersey (or old REST api) with the current (2.3.1) one.
Also the package you are working in (com.sun.jersey
- the 'old' Jersey package) points a bit towards this direction (although just placing your code into that package itself cannot cause the mentioned problem), you obviously started with the Jersey 1.x example as a base (there are samples in Jersey 2 as well, see helloworld-webapp on Jersey GitHub).
Is it possible, that restEasy (also definitely containing the javax.ws.rs.core.Application
class) is not completely switched off and somehow defaults to JAX-RS 1.x version?
I would start with inspecting your pom file, look at the effective pom (if your project descriptor has some parent) and check carefully what is on your classpath - I believe there is a 1.x version of javax.ws.rs-api
somewhere. Also try to clean all the compiled stuff and rebuild from scratch.
Speaking of dependencies, if your list is exhaustive (regarding Jersey), you will most likely have to add jersey-common
(2.3.1) dependency, as already during the initialization, the ResourceConfig.packages()
method calls the PackageScanner
constructor, which contains call to ReflectionHelper
- and this is not a part of the server jar any more.
Hope this helps.
Solution 2:
I faced same problem recently. I thought share my steps for you. As the other answers state, the problem is mainly because of having two different versions of the same class on your classpath. So when you add maven dependencies in your pom be careful.
These kind of problems are normally called as Jar Hell. You can use jhades API for investigate the classes overlap one another. Here is the simple steps i have followed.
Add jhades dependency into your pom.
<dependency>
<groupId>org.jhades</groupId>
<artifactId>jhades</artifactId>
<version>1.0.4</version>
</dependency>
Show the report
Call new JHades().overlappingJarsReport();
in your main
method, it will output to stdout.
Sample Output:
file:/Users/justin/.m2/repository/javax/ws/rs/jsr311-api/1.1.1/jsr311-api-1.1.1.jar overlaps with
file:/Users/justin/.m2/repository/javax/ws/rs/javax.ws.rs-api/2.0/javax.ws.rs-api-2.0.jar - total overlapping classes: 55 - same classloader ! This is an ERROR!
Remove one of overlap maven dependency in your pom.
Also you can use another approach like maven's dependency exclusions.
Source: Blog post on jhades
Hope this will help someone :)
Solution 3:
Just got this working on JBoss EAP 6.1.1 - Jersey 2.3.1.
The usual things don't seem to work/are not enough on their own:
- disabling the jaxrs-subsystem in standalone.xml/domain.xml
- or, excluding the jax-rs modules in jboss-deployment-structure.xml
Additionaly you need to disable the loading of the jax-rs 1.1 API completely by modifying module.xml in jboss-eap-6.1/modules/system/layers/base/javax/ws/rs/api/main/module.xml like this:
<module xmlns="urn:jboss:module:1.1" name="javax.ws.rs.api">
<resources>
<!-- Disable the next line -->
<!-- resource-root path="jboss-jaxrs-api_1.1_spec-1.0.1.Final-redhat-2.jar"/ -->
<!-- Insert resources here -->
</resources>
<dependencies>
<module name="org.jboss.resteasy.resteasy-jaxrs" services="export"/>
</dependencies>
</module>
Please note that this will disable the jax-rs implementation of JBoss (RestEasy) for all other applications as well (as does disabling the jaxrs subsystem in standalone/domain.xml).