Axis2 Webservice new RPCServiceClient()错误的问题

参照网上的例子写了一个AXIS2的客户端例子,在此感谢各位前辈的无私奉献!同时也分享一下,供各位朋友指导!

服务端代码:

import java.util.Random;

public class HelloWorldService {

    public String sayHello(String name) {
        return name + "! say:hello [axis2 ]";
    }

    public int getAge(int i) {
        return i + new Random().nextInt(100);
    }
}

客户端代码:

package client;

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;

public class HelloWordClient {
	public static void main(String[] args) throws AxisFault {
		
		RPCServiceClient client = new RPCServiceClient();
		Options options = client.getOptions();
		String address = "http://localhost:8080/axis2/services/HelloWorldService";
		EndpointReference epf = new EndpointReference(address);
		options.setTo(epf);
		
		QName qName = new QName("http://ws.apache.org/axis2","sayHello");
		Object[] result = client.invokeBlocking(qName, new Object[]{"winter"}, new Class[]{String.class});
		System.out.println(result[0]);
		
		qName=new QName("http://ws.apache.org/axis2","getAge");
		result = client.invokeBlocking(qName, new Object[]{ new Integer(22) } , new Class[] {int.class});
		System.out.println(result[0]);
	}
}

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

axiom-api-1.2.13.jar
axiom-impl-1.2.13.jar
axis2-adb-1.6.2.jar
axis2-kernel-1.6.2.jar
axis2-transport-http-1.6.2.jar
axis2-transport-local-1.6.2.jar
commons-codec-1.3.jar
commons-httpclient-3.1.jar
commons-logging-1.1.1.jar
httpcore-4.0.jar
neethi-3.0.2.jar
wsdl4j-1.6.2.jar
XmlSchema-1.4.7.jar

以上代码来自网上


但是在采用rpc方式时,可能会报如下错误

Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/internet/ParseException
	at org.apache.axis2.util.XMLUtils.toOM(XMLUtils.java:590)
	at org.apache.axis2.util.XMLUtils.toOM(XMLUtils.java:575)
	at org.apache.axis2.deployment.DescriptionBuilder.buildOM(DescriptionBuilder.java:97)
	at org.apache.axis2.deployment.AxisConfigBuilder.populateConfig(AxisConfigBuilder.java:90)
	at org.apache.axis2.deployment.DeploymentEngine.populateAxisConfiguration(DeploymentEngine.java:857)
	at org.apache.axis2.deployment.FileSystemConfigurator.getAxisConfiguration(FileSystemConfigurator.java:116)
	at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContext(ConfigurationContextFactory.java:64)
	at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContextFromFileSystem(ConfigurationContextFactory.java:210)
	at org.apache.axis2.client.ServiceClient.configureServiceClient(ServiceClient.java:151)
	at org.apache.axis2.client.ServiceClient.(ServiceClient.java:144)
	at org.apache.axis2.client.ServiceClient.(ServiceClient.java:251)
	at org.apache.axis2.rpc.client.RPCServiceClient.(RPCServiceClient.java:48)
	at client.GetServuce.main(GetServuce.java:13)

这是因为缺少mail-1.4.jar


你可能感兴趣的:(Axis2 Webservice new RPCServiceClient()错误的问题)