基于CXF的webService本地数据交互----PC端与Android端(二)

 

服务端以maven的形式创建项目。

 

项目创建好后,其结构如图:
基于CXF的webService本地数据交互----PC端与Android端(二)_第1张图片

 

关于客户端测试代码(PC和android端)和服务端的接口及实现代码可参考

基于CXF的webService本地数据交互----PC端与Android端(一)

代码不变。

 

用maven主要是包的导入问题(pom.xml),对于这块我试了好久啊。

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>com.royal</groupId>
	<artifactId>cxf_webservice</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>cxf_webservice</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>aopalliance</groupId>
			<artifactId>aopalliance</artifactId>
			<version>1.0</version>
		</dependency>
		<dependency>
			<groupId>asm</groupId>
			<artifactId>asm</artifactId>
			<version>3.3</version>
		</dependency>
		<dependency>
			<groupId>commons-logging</groupId>
			<artifactId>commons-logging</artifactId>
			<version>1.1.1</version>
		</dependency>
		<!-- 这里由于连网下载不下来,可以手动下载CXF版本的包,然后自己手动加进去,添加的方法直接将cxf-2.4.6.jar放到.m2/repository/org/apache/cxf/cxf/2.4.6/的文件夹下。手动添加jar包都是这么干的。 -->
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf</artifactId>
			<version>2.4.6</version>
		</dependency>
		<dependency>
			<groupId>org.apache.geronimo.specs</groupId>
			<artifactId>geronimo-activation_1.1_spec</artifactId>
			<version>1.1</version>
		</dependency>
		<dependency>
			<groupId>org.apache.geronimo.specs</groupId>
			<artifactId>geronimo-annotation_1.0_spec</artifactId>
			<version>1.1.1</version>
		</dependency>
		<dependency>
			<groupId>org.apache.geronimo.specs</groupId>
			<artifactId>geronimo-javamail_1.4_spec</artifactId>
			<version>1.7.1</version>
		</dependency>
		<!-- <dependency> -->
		<!-- <groupId>org.apache.geronimo.specs</groupId> -->
		<!-- <artifactId>geronimo-servlet_2.5_spec</artifactId> -->
		<!-- <version>1.1.2</version> -->
		<!-- </dependency> -->
		<dependency>
			<groupId>org.apache.geronimo.specs</groupId>
			<artifactId>geronimo-ws-metadata_2.0_spec</artifactId>
			<version>1.1.3</version>
		</dependency>
<!-- 		<dependency> -->
<!-- 			<groupId>javax.xml.bind</groupId> -->
<!-- 			<artifactId>jaxb-api</artifactId> -->
<!-- 			<version>2.2.3</version> -->
<!-- 		</dependency> -->
<!-- 		<dependency> -->
<!-- 			<groupId>com.sun.xml.bind</groupId> -->
<!-- 			<artifactId>jaxb-impl</artifactId> -->
<!-- 			<version>2.2.4-1</version> -->
<!-- 		</dependency> -->
		<dependency>
			<groupId>org.apache.neethi</groupId>
			<artifactId>neethi</artifactId>
			<version>3.0.1</version>
		</dependency>
		<!-- 这个也是手动添加的 -->
		<dependency>
			<groupId>org.mortbay.jetty</groupId>
			<artifactId>jetty-util</artifactId>
			<version>7.4.5.v20110725</version>
		</dependency>
<!-- 		<dependency> -->
<!-- 			<groupId>javax.xml.soap</groupId> -->
<!-- 			<artifactId>saaj-api</artifactId> -->
<!-- 			<version>1.3.4</version> -->
<!-- 		</dependency> -->
<!-- 		<dependency> -->
<!-- 			<groupId>com.sun.xml.messaging.saaj</groupId> -->
<!-- 			<artifactId>saaj-impl</artifactId> -->
<!-- 			<version>1.3.12</version> -->
<!-- 		</dependency> -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aop</artifactId>
			<version>3.1.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>
			<version>3.1.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-asm</artifactId>
			<version>3.1.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>3.1.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>3.1.0.RELEASE</version>
		</dependency>
		<!-- spring-web包一加载,老是报这个错:org.xml.sax.SAXParseException: The entity "nbsp" was referenced, but not declared.--> 
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>3.1.0.RELEASE</version>  
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-expression</artifactId>
			<version>3.1.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.codehaus.woodstox</groupId>
			<artifactId>stax2-api</artifactId>
			<version>3.1.1</version>
		</dependency>
		<dependency>
			<groupId>wsdl4j</groupId>
			<artifactId>wsdl4j</artifactId>
			<version>1.6.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.ws.xmlschema</groupId>
			<artifactId>xmlschema-core</artifactId>
			<version>2.0.1</version>
		</dependency>
	</dependencies>
</project>
 
org.xml.sax.SAXParseException: The entity "nbsp" was referenced, but not declared.

报这个错其实可以不用理他,做的时候我还一直纠结着,具体怎么解决我还是也不知道。

maven从网上下载包请取消Offline选项
基于CXF的webService本地数据交互----PC端与Android端(二)_第2张图片

最后down下来的包有这些
基于CXF的webService本地数据交互----PC端与Android端(二)_第3张图片
 
beanRefServer.xml

<?xml version="1.0" encoding="UTF-8"?>

	<!-- START SNIPPET: beans -->
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">


	<!-- Import Apache CXF Bean Definition -->
	<import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

	<!-- implementor :接口类的实现类 address: 要和注释里面神秘的服务名对应, -->
	<jaxws:endpoint id="helloWorld"
		implementor="com.royal.serviceImpl.HelloWorldImpl" address="/HelloWorldService" />

</beans>

 

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
	
	<!-- Spring Config Location -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/beanRefServer.xml</param-value>
    </context-param>
    Spring ContextLoaderListener
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    
     <!-- Apache CXFServlet -->
    <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>
            org.apache.cxf.transport.servlet.CXFServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <!-- CXFServlet Mapping -->
    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
	
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

 

项目文件所有都OK后,maven的部署,注意一定要清楚缓存啊。一个干净的环境很重要。

 

右键项目---属性---tomcat
基于CXF的webService本地数据交互----PC端与Android端(二)_第4张图片

注意勾选部署前的jar包
基于CXF的webService本地数据交互----PC端与Android端(二)_第5张图片

再来2步操作

project---clean,  project----update all maven dependencies

 

这下干净了,启动Tomcat。

 

测试结果
基于CXF的webService本地数据交互----PC端与Android端(二)_第6张图片

你可能感兴趣的:(maven,android,CXF,pc,数据交互)