我正在运行 Websphere Liberty Profile V8.5,并且正在尝试部署一个使用 restful 服务来公开一些 CRUD 数据库操作的网站。部署工作正常,但在运行时,当我在根目录下的浏览器中打开网站时,我看到:
[错误] Uncaught.init.exception.thrown.by.servlet
Jersey 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>