标签:java String HelloWS WebService 即时 apache org AXIS axis
使用Axis的服务平台,创建和发布WebService;
发布服务手段;
即时发布JWS
1编写Java代码:定制服务(编写类—方法);
2修改文件的后缀jws;
3发布web service服务;
4编写客户端;
注意:如果没有java的源码(class/jar/程序存在package结构)--不能使用JWS定制;
1 下载地址:
http://axis.apache.org/axis2/java/core/download.cgi
axis-bin-1_4下载地址
http://ishare.iask.sina.com.cn/f/14151767.html
2 部署axis-bin-1_4\axis-1_4\webapps\axis
3 异常
- No compiler found in your classpath! (you may need to add 'tools.jar') java.lang.ClassNotFoundException: sun.tools.javac.Main |
java.lang.RuntimeException: No compiler found in your classpath! (you may need to add 'tools.jar') at org.apache.axis.components.compiler.Javac.<init>(Javac.java:72) |
- No compiler found in your classpath! (you may need to add 'tools.jar') java.lang.ClassNotFoundException: sun.tools.javac.Main at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526) |
把jdk下的tool.jar拷贝到工程目录下即可;
4 定义一个服务类,并发布
public class HelloWS { public String test(String a,String b){ "a="+a +"b="+b; return"server response ok,you send " } } |
注意:
1)没有指定包名
2)将此文件HelloWS.java改成HelloWS.jws;
3)将HelloWS.jws文件放到服务下;
5 调用上面发布的服务类
package com.client; import javax.xml.namespace.QName; import org.apache.axis.client.Call; import org.apache.axis.client.Service; public class ClientJWS { public static void main(String[] args) { try { //定义字符串,描述要访问的服务器地址 "http://localhost:8080/axis/HelloWS.jws"; //创建一个Web Service的服务 Service service = new Service(); //创建一个调用 Call call = (Call)service.createCall(); //指定服务来源 call.setTargetEndpointAddress(url); //指定调用的具体的方法名 call.setOperationName(new QName(url,"test")); //执行远端调用 String result = (String)call.invoke(new Object[]{"Student","Teacher"}); System.out.println(result); } catch (Exception e) { e.printStackTrace(); } } } |
标签:java,
String,
HelloWS,
WebService,
即时,
apache,
org,
AXIS,
axis
From: https://blog.51cto.com/u_15739274/5749396