1 建立Eclipse插件
File->New->Project->Plug-in development的Plug-in project->Next,填写Project名,Next, 填写内容,Next,选择Create plug-in using one of the templates,选择Hello,World,Finish。
在视图可看到plugin.xml,在<Runtime>里加上运行调用Web Service所需jar包。内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin
id="colimas_plugin"
name="Colimas_plugin Plug-in"
version="1.0.0"
provider-name="nova"
class="colimas_plugin.Colimas_pluginPlugin">
<runtime>
<library name="colimas_plugin.jar">
<export name="*"/>
</library>
<library name="lib/activation.jar">
<export name="*"/>
</library>
<library name="lib/axis.jar">
<export name="*"/>
</library>
<library name="lib/commons-beanutils.jar">
<export name="*"/>
</library>
<library name="lib/commons-discovery-0.2.jar">
<export name="*"/>
</library>
<library name="lib/commons-logging-1.0.4.jar">
<export name="*"/>
</library>
<library name="lib/jaxrpc.jar">
<export name="*"/>
</library>
<library name="lib/xalan.jar">
<export name="*"/>
</library>
<library name="lib/xerces.jar">
<export name="*"/>
</library>
<library name="lib/saaj.jar">
<export name="*"/>
</library>
<library name="lib/mail.jar">
<export name="*"/>
</library>
</runtime>
<requires>
<import plugin="org.eclipse.ui"/>
<import plugin="org.eclipse.core.runtime"/>
</requires>
<extension
point="org.eclipse.ui.actionSets">
<actionSet
label="Sample Action Set"
visible="true"
id="colimas_plugin.actionSet">
<menu
label="Sample &Menu"
id="sampleMenu">
<separator
name="sampleGroup">
</separator>
</menu>
<action
label="&Sample Action"
icon="icons/sample.gif"
class="colimas_plugin.actions.SampleAction"
tooltip="Hello, Eclipse world"
menubarPath="sampleMenu/sampleGroup"
toolbarPath="sampleGroup"
id="colimas_plugin.actions.SampleAction">
</action>
</actionSet>
</extension>
</plugin>
2 建立调用Web Service类,该类实现调用Axis的WebService。
/*
* Created on 2005/07/30
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.nova.colimas.plugin.eclipse;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import java.io.*;
/**
* @author tyrone
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class SendFileClient {
private Call call;
/**
* The constructor.
*/
public SendFileClient() {
try{
Service service= new Service();
call = (Call) service.createCall();
}catch(Exception ex){
System.out.println(ex.getMessage());
}
}
public void saveFile(){
try {
String endpoint =
"http://localhost:8080/axis/services/DocumentFileManagement";
System.out.println("start web service");
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName(new QName("http://soapinterop.org/", "saveFile"));
File fp=new File("D:\\MyProject\\colimas\\colimas_plugin\\lib\\mail.jar");
BufferedInputStream in=new BufferedInputStream(new FileInputStream(fp));
int len=in.available();
byte[] contents=new byte[len];
in.read(contents,0,len);
System.out.println("begin run");
//开始调用Web Service:DocumentFileManagement的saveFile方法
String ret = (String) call.invoke( new Object[] {fp.getName(),contents} );
in.close();
} catch (Exception e) {
System.err.println("error"+e.toString());
}
}
}
3 修改Action类的run方法
Action类的run方法里的内容是Eclipse插件真正要做到事
package colimas_plugin.actions;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.jface.dialogs.MessageDialog;
import com.nova.colimas.plugin.eclipse.*;
/**
* Our sample action implements workbench action delegate.
* The action proxy will be created by the workbench and
* shown in the UI. When the user tries to use the action,
* this delegate will be created and execution will be
* delegated to it.
* @see IWorkbenchWindowActionDelegate
*/
public class SampleAction implements IWorkbenchWindowActionDelegate {
private IWorkbenchWindow window;
/**
* The constructor.
*/
public SampleAction() {
}
/**
* The action has been activated. The argument of the
* method represents the 'real' action sitting
* in the workbench UI.
* @see IWorkbenchWindowActionDelegate#run
*/
public void run(IAction action) {
SendFileClient client=new SendFileClient();
client.saveFile();
MessageDialog.openInformation(
window.getShell(),
"Colimas_plugin Plug-in",
"Colimas Connected");
}
/**
* Selection in the workbench has been changed. We
* can change the state of the 'real' action here
* if we want, but this can only happen after
* the delegate has been created.
* @see IWorkbenchWindowActionDelegate#selectionChanged
*/
public void selectionChanged(IAction action, ISelection selection) {
}
/**
* We can use this method to dispose of any system
* resources we previously allocated.
* @see IWorkbenchWindowActionDelegate#dispose
*/
public void dispose() {
}
/**
* We will cache window object in order to
* be able to provide parent shell for the message dialog.
* @see IWorkbenchWindowActionDelegate#init
*/
public void init(IWorkbenchWindow window) {
this.window = window;
}
}
4 调试
首先启动Axis服务器,然后选择Eclipse的Run菜单的Run As -〉Run time workbench。
这样会启动另一个Eclipse workbench,在这个workbench里你会看到toolbar里新增了一个按钮,
点击按钮就会调用Webservice并返回控制台结果。
分享到:
相关推荐
webservice开发,axis的eclipse客户端插件,用于生成webservice客户端代码
Axis2_Codegen_Wizard_1.4.0( eclipse中Webservice客户端生成插件), 方便各位需要调用Webservice,生成客户端程序的同学
使用Eclipse的Axis1.4插件开发Web Service及客户端
eclipse,myeclipse反向生成webservice客户端插件,将文件夹解压到\MyEclipse 8.5\dropins\目录下重启Mycelipse,在Myeclipse中选择import Axis2 Code Generator项目即可反向生成webservice客户端代码1.4版本,可以...
eclipse,myeclipse反向生成webservice客户端插件,将文件夹解压到\MyEclipse 8.5\dropins\目录下重启Mycelipse,在Myeclipse中选择import Axis2 Code Generator项目即可反向生成webservice客户端代码1.6版本
axis2支持webservice 自动生成代码客户端服务端代码 基于eclipse
myeclipse安装axis2.txt文件:详细说明了myeclipse如何安装axis2插件,以及编写简单的服务端代码,以及axis2客户端访问服务端的几种方式。 axisdemo是一个普通的javaweb工程,里面有一个简单的接口,在此工程的基础...
axis2-1.7.7 eclipse最新的webservice开发插件,附件包含服务端和客户端插件
myeclipse安装axis2.txt文件:详细说明了myeclipse如何安装axis2插件,以及编写简单的服务端代码,以及axis2客户端访问服务端的几种方式。 axisdemo是一个普通的javaweb工程,里面有一个简单的接口,在此工程的基础...
AXIS2 最新版本1.7.3针对 eclipse插件,一方面可以根据java接口类生成WSDL文件,另一方面可以根据WSDL生成客户端或服务端代码,生成的WSDL文件和代码符合web server SOAP协议规范标准!解压后的jar复制到Eclipse的...
myeclipse安装axis2.txt文件:详细说明了myeclipse如何安装axis2插件,以及编写简单的服务端代码,以及axis2客户端访问服务端的几种方式。 axisdemo是一个普通的javaweb工程,里面有一个简单的接口,在此工程的基础...
axis2实现webservice,在Eclipse中打包aar文件插件、新建web service client客户端插件。在Eclipse中新建选项会出现 Axis2 Wizards Axis2 Code Generator Axis2 Service Archiver Web Service Client 等。 资源包括...
eclipse 工具通过axis2插件,根据wsdl生成webservice客户端代码。将此文件解压缩,放到%eclipse_home%\eclipse\plugins中,重启eclipse。然后选中项目,新建-other-axis2 wizards 下的axis2 code generate ,然后...
axis2eclipse插件,自动生成webservice服务端客户端代码,方便开发
使用axis2开发webservice时,在eclipse中需要使用的两个插件,可以将service类文件转换为wsdl文件,然后将wsdl文件转换为客户端和服务端的框架代码,并在tomcat上发布服务
简单易懂的axis2示例,包含了文档、开发的ant脚本。结合这eclipse插件最好了