AXIS2最简单客户端jar包说明及错误对照

来源:互联网 发布:淘宝网页如何制作 编辑:程序博客网 时间:2024/06/01 07:24
参照网上的例子写了一个AXIS2的客户端例子,在此感谢各位前辈的无私奉献!同时也分享一下,供各位朋友指导!

服务端代码:

  1. import java.util.Random;  
  2.   
  3. public class HelloWorldService {  
  4.   
  5.     public String sayHello(String name) {  
  6.         return name + "! say:hello [axis2 ]";  
  7.     }  
  8.   
  9.     public int getAge(int i) {  
  10.         return i + new Random().nextInt(100);  
  11.     }  

客户端代码:

  1. package client;  
  2.   
  3. import javax.xml.namespace.QName;  
  4.   
  5. import org.apache.axis2.AxisFault;  
  6. import org.apache.axis2.addressing.EndpointReference;  
  7. import org.apache.axis2.client.Options;  
  8. import org.apache.axis2.rpc.client.RPCServiceClient;  
  9.   
  10. public class HelloWordClient {  
  11.     public static void main(String[] args) throws AxisFault {  
  12.           
  13.         RPCServiceClient client = new RPCServiceClient();  
  14.         Options options = client.getOptions();  
  15.         String address = "http://localhost:8080/axis2/services/HelloWorldService";  
  16.         EndpointReference epf = new EndpointReference(address);  
  17.         options.setTo(epf);  
  18.           
  19.         QName qName = new QName("http://ws.apache.org/axis2","sayHello");  
  20.         Object[] result = client.invokeBlocking(qName, new Object[]{"winter"}, new Class[]{String.class});  
  21.         System.out.println(result[0]);  
  22.           
  23.         qName=new QName("http://ws.apache.org/axis2","getAge");  
  24.         result = client.invokeBlocking(qName, new Object[]{ new Integer(22) } , new Class[] {int.class});  
  25.         System.out.println(result[0]);  
  26.     }  

以上代码接来源于网络!

下面才是我重点想说的内容,也是我一样的初学者比较困惑的jar包问题,经我实际测试所需的最少jar包为

  1. axiom-api-1.2.13.jar  
  2. axiom-impl-1.2.13.jar  
  3. axis2-adb-1.6.2.jar  
  4. axis2-kernel-1.6.2.jar  
  5. axis2-transport-http-1.6.2.jar  
  6. axis2-transport-local-1.6.2.jar  
  7. commons-codec-1.3.jar  
  8. commons-httpclient-3.1.jar  
  9. commons-logging-1.1.1.jar  
  10. httpcore-4.0.jar  
  11. neethi-3.0.2.jar  
  12. wsdl4j-1.6.2.jar  
  13. XmlSchema-1.4.7.jar 
下面是缺少jar包和相关的错误说明:

  1. XmlSchema-1.4.7.jar           
  2. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/ws/commons/schema/resolver/URIResolver  
  3.   
  4. axiom-impl-1.2.13.jar             
  5. Exception in thread "main" org.apache.axiom.om.OMException: No meta factory found for feature 'default'; this usually means that axiom-impl.jar is not in the classpath   
  6.   
  7. neethi-3.0.2.jar              
  8. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/neethi/PolicyComponent  
  9.   
  10. axis2-transport-http-1.6.2.jar        
  11. Exception in thread "main" org.apache.axis2.deployment.DeploymentException: org.apache.axis2.transport.http.CommonsHTTPTransportSender  
  12.   
  13. axis2-transport-local-1.6.2.jar       
  14. Exception in thread "main" org.apache.axis2.deployment.DeploymentException: org.apache.axis2.transport.local.LocalTransportSender     
  15.   
  16. commons-codec-1.3.jar             
  17. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException  
  18.   
  19. commons-httpclient-3.1.jar        
  20. Exception in thread "main" org.apache.axis2.deployment.DeploymentException: org/apache/commons/httpclient/HttpException  
  21.   
  22. httpcore-4.0.jar              
  23. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpResponseFactory  
  24.   
  25. wsdl4j-1.6.2.jar              
  26. Exception in thread "main" java.lang.NoClassDefFoundError: javax/wsdl/xml/WSDLLocator

0 0
原创粉丝点击