我试图站起来[基本的cxf rs示例] [1],但是使用我自己的服务impl
,它甚至更简单,我的所有方法都返回字符串。当我尝试运行此服务器时,我得到此异常
我建立了一个干净的项目,所以我开始新鲜......
掌握pom http://maven.apache.org/xsd/maven-4.0.0.xsd“>
<modelVersion>4.0.0</modelVersion>
<name>Tests</name>
<groupId>com.crush</groupId>
<artifactId>tests</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<properties>
<cxf.version>2.7.11</cxf.version>
<httpclient.version>3.1</httpclient.version>
<rs-api.version>2.0</rs-api.version>
<disclaimer/>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j.version>1.6.2</slf4j.version>
<guava.version>13.0-rc2</guava.version>
<jgroups.version>3.1.0.Final</jgroups.version>
<infinispan.version>5.1.4.CR1</infinispan.version>
<commons.cli.version>1.2</commons.cli.version>
<jettison.version>1.3.2</jettison.version>
<spring.version>3.1.0.RELEASE</spring.version>
<bouncycastle.version>1.46</bouncycastle.version>
<junit.version>4.8</junit.version>
<jasypt.version>1.9.0</jasypt.version>
<!-- Additional Dependencies -->
<cxf.buildtools.version>2.2.12</cxf.buildtools.version>
<!-- Maven Plugin Versions -->
<shade.plugin.version>1.7.1</shade.plugin.version>
<buildnumber.plugin.version>1.1</buildnumber.plugin.version>
<jar.plugin.version>2.4</jar.plugin.version>
<resources.plugin.version>2.5</resources.plugin.version>
<versions.plugin.version>1.3.1</versions.plugin.version>
<!-- Plugin Versions -->
<compiler.plugin.version>2.4</compiler.plugin.version>
<surefire.plugin.version>2.12.4</surefire.plugin.version>
<skipTests>true</skipTests>
<jboss.cache.version>3.2.5.GA</jboss.cache.version>
<maven.build.timestamp.format>yyyyMMdd-HHmmss</maven.build.timestamp.format>
</properties>
<modules>
<module>sample-service</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- This dependency is needed if you're using the Jetty container -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${rs-api.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<!-- This plugin is used update the version numbers of the project
during the release process. -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>${versions.plugin.version}</version>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<!-- Plugin configuration for the plugin that specifies the base file encoding. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${resources.plugin.version}</version>
<configuration>
<encoding>UTF-8</encoding>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler.plugin.version}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
样本服务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/maven- v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.crush</groupId>
<artifactId>tests</artifactId>
<version>1.0</version>
</parent>
<artifactId>sample-service</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Simple CXF project using spring configuration</name>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
</dependencies>
<profiles>
<profile>
<id>server</id>
<build>
<defaultGoal>test</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.crush.tests.service.Test</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.crush.tests.service.Test</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
MANIFEST.MF 清单 - 版本:1.0 Archiver-版本:Plexus Archiver 创建者:Apache Maven 内置:暗恋 Build-Jdk:1.7.0_55
SampleServiceImpl
package com.crush.tests.service.ws.impl;
import javax.jws.WebService;
import com.crush.tests.service.ws.SampleService;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
impo rt javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
@WebService(endpointInterface = "com.crush.tests.service.ws.SampleService")
@Path("/sample/")
@Produces("text/xml")
public class SampleServiceImpl implements SampleService
{
public SampleServiceImpl()
{
}
@GET
@Path("/hi/{text}")
public String sayHi(@PathParam("text") String text)
{
return "Hello " + text;
}
}
当我运行时:mvn -Pserver
2014年6月27日下午3:10:26 org.apache.cxf.endpoint.ServerImpl initDestination
信息:将服务器的发布地址设置为http:// localhost:9000 /
SLF4J:无法加载类“org.slf4j.impl.StaticLoggerBinder”。
SLF4J:默认为无操作(NOP)记录器实现
SLF4J:有关详细信息,请参阅http://www.slf4j.org/codes.html#StaticLoggerBinder
服务器就绪......
如果我浏览sample-service-1.0-jar-with-dependencies.jar,我可以导航到/ org / apache / cxf / transport(s)以及查找依赖jar中的任何类。
答案 0 :(得分:4)
问题是cxf类需要在类路径上设置,即使它们被捆绑到我的jar中......没有理由为什么但是那就是修复。
答案 1 :(得分:1)
似乎使用清单而不是使用java -cp
以下是不同的:
使用classpath,Classloader找到几个带META-INF/cxf/bus-extensions.txt
的jar但只有manifest的cxf-core(没有定义http传输)