0

I'm running Websphere Liberty Profile V8.5 and I'm trying to deploy a website that uses a restful service to expose some CRUD db operations. Deployment works fine but during runtime when I open the website in a browser at the root I see this:

[ERROR ] Uncaught.init.exception.thrown.by.servlet
Jersey REST Service
developer-portal
java.lang.NoClassDefFoundError: Could not initialize class org.apache.wink.common.internal.providers.header.MediaTypeHeaderDelegate

I strongly believe it has something to do with my dependencies. As you will see, I tried manually adding org.apache.wink.common.internal.privders.header.MediaTypeHeaderDelegate to no avail. Here is my POM file:

<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>developer-portal</groupId>
  <artifactId>developer-portal</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>developer-portal</name>
  <url>http://maven.apache.org</url>

  <properties>
    <serverName>dropServer</serverName>
    <serverHome>C:\wlp</serverHome>
    <was.install.dir>C:/wlp/</was.install.dir>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <pluginRepositories>
    <pluginRepository>
        <id>Liberty</id>
        <name>Liberty Repository</name>
        <url>http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/</url>
        <layout>default</layout>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </pluginRepository>
  </pluginRepositories>

  <repositories>
    <repository>
        <id>Liberty</id>
        <name>Liberty Repository</name>
        <url>http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
        <groupId>com.ibm.tools.target</groupId>
        <artifactId>was-liberty</artifactId>
        <version>8.5.5</version>
        <type>pom</type>
        <scope>compile</scope>
    </dependency>
    <dependency> <!-- Hard-Coded, made-up dependency -->
        <groupId>com.ibm.nosql</groupId>
        <artifactId>nosqljson</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>C:\javalib\db2_drivers\nosqljson.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>1.18</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.18</version>
    </dependency>
    <dependency>
        <groupId>org.apache.wink</groupId>
        <artifactId>wink-assembly-aggregatejar-osgi</artifactId>
        <version>1.2.1-incubating</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.jersey-test-framework</groupId>
        <artifactId>jersey-test-framework-core</artifactId>
        <version>1.17.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-email</artifactId>
        <version>1.3.2</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>developer-portal</finalName>
    <plugins>
        <plugin>
            <groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
            <artifactId>liberty-maven-plugin</artifactId>
            <version>1.0</version>
            <executions>
                <execution>
                    <id>start-server</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>start-server</goal>
                    </goals>
                    <configuration>
                        <serverHome>${serverHome}</serverHome>
                        <serverName>${serverName}</serverName>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
            <artifactId>liberty-maven-plugin</artifactId>
            <version>1.0</version>
            <configuration>
                <serverHome>${serverHome}</serverHome>
                <serverName>${serverName}</serverName>
            </configuration>
            <executions>
                <execution>
                    <id>deployapp</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>deploy</goal>
                    </goals>
                    <configuration>
                        <appArchive>${project.build.directory}/${project.name}.war</appArchive>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>
  </build>

</project>

Web.xml snippet:

<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>websphere.jaxrs.app.ApplicationConfig</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
user2316667
  • 5,444
  • 13
  • 49
  • 71

1 Answers1

0

Liberty provides JAX-RS 1.1 runtime, so try not to include any jaxrs libraries with your application. Ensure that you jaxrs feature is enabled in your server.xml using:

<feature>jaxrs-1.1</feature>

and try to change your web.xml the following way:

<servlet>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
</servlet>
<servlet-mapping>
   <servlet-name>javax.ws.rs.core.Application</servlet-name>
   <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Gas
  • 17,601
  • 4
  • 46
  • 93
  • Thanks a lot but I necessarily need to use Jersey. I have it working in a separate project where I manually import JARs but not with maven. – user2316667 Aug 13 '14 at 12:49
  • In that case, its a maven issue. Compare application that you created manually with one built with maven and see what is missing. – Gas Aug 13 '14 at 21:33