2

I am trying to deploy my first rest application using jersey 2.17.

I am using Maven, GlassFish 3.1.2.2 for deployment.

Application runs in eclipse (tomcat), but gives following error when deploying through glassfish admin console.

Error occurred during deployment: Exception while loading the app :
  java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException:
  java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;. 
Please see server.log for more details.

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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>JerseyExample</groupId>
    <artifactId>JerseyExample</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>2.17</version>
        </dependency>
    </dependencies>
</project>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>JerseyExample</display-name>
    <servlet>
        <servlet-name>MyJerseyExample</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>jerseyExample.resource</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>MyJerseyExample</servlet-name>
        <url-pattern>/example/*</url-pattern>
    </servlet-mapping>
</web-app>
Bhushan
  • 6,151
  • 13
  • 58
  • 91
  • 2
    Glassfish already has an internal Jersey implementation. Unfortunately 3.x uses a Jersey 1.x version. The problem you are facing is a result of mixing Jersey 2.x with Jersey 1.x. I have no idea how to update Glassfish 3.x to use Jersey 2.x. I forget where I read it, but I think part of Glassfish uses Jersey for some other features, so to disable it might not be possible (or at best break something in Glassfish). If you are looking for Jersey 2.x specific features, maybe upgrade to Glassfish 4.x. Otherwise, you might be stuck with using Jersey 1.x – Paul Samsotha Jun 09 '15 at 05:14
  • NoSuchMethodError usually means you are having two different versions of the class on your classpath. – Arjit Jun 09 '15 at 05:21
  • You can try replacing the javax.ws.rs-api in your glass-fish server. Location, for example, may look like this: "C:\Program Files\glassfish-4.1\glassfish\modules". Please replace with 2.0 version or as others said you can upgrade to glassfish-4. – geekprogrammer Jun 09 '15 at 05:21

1 Answers1

5

Ok looked at your issue. The External Glassfish v 3.1.2.2 that you are using is JAVA-EE 6 compatible. And the one through which you are running your app in eclipse is JAVA-EE 7 compatible.

Have a look at both the java docs:

Application class Java Doc for EE6

Application class Java Doc for EE7

You will see that the getProperties method got introduced in JAVA-EE 7.

Simply upgrade to glassfish version-4.x that is compatible with JAVA-EE 7. Assuming nothing else breaks should be good.

Himanshu Bhardwaj
  • 4,038
  • 3
  • 17
  • 36