我正在运行Websphere Liberty Profile V8.5,而且我正在尝试部署使用restful服务的网站来公开某些CRUD数据库操作。部署工作正常,但在运行时,当我在根目录的浏览器中打开网站时,我看到:
[ERROR] Uncaught.init.exception.thrown.by.servlet
泽西REST服务
开发者门户
java.lang.NoClassDefFoundError:无法初始化类 org.apache.wink.common.internal.providers.header.MediaTypeHeaderDelegate
我坚信它与我的依赖关系有关。正如您将看到的,我尝试手动添加org.apache.wink.common.internal.privders.header.MediaTypeHeaderDelegate无济于事。这是我的POM文件:
<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片段:
<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>
答案 0 :(得分:0)
Liberty提供JAX-RS 1.1运行时,因此尽量不要在应用程序中包含任何jaxrs库。确保使用以下内容server.xml
启用了jaxrs功能:
<feature>jaxrs-1.1</feature>
并尝试按以下方式更改web.xml
:
<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>