1. Create an Eclipse plug-in
File-> New-> Project-> plug-in Development's plug-in project-> next, fill in the project name, next, fill in the content, next, select create plug-in using one of the templates, select Hello, world, and finish.
You can see plugin. XML in the view, and add the jar package required for running the Web service in <runtime>. The content is as follows:
<? 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 = "Library/commons-beanutils.jar">
<Export name = "*"/>
</Library>
<Library name = "Library/commons-discovery-0.2.jar">
<Export name = "*"/>
</Library>
<Library name = "Library/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 & amp; menu"
Id = "samplemenu">
<Separator
Name = "samplegroup">
</Separator>
</Menu>
<Action
Label = "& amp; 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. Create a WebService class that calls axis.
/*
* Created on 2005/07/30
*
* Todo to change the template for this generated file go
* 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
* Window-preferences-Java-code style-code templates
*/
Public class sendfileclient {
Private call;
/**
* The constructor.
*/
Public sendfileclient (){
Try {
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 ");
// Start to call Web Service:DocumentfilemanagementSaveFile method
String ret = (string) Call. Invoke (new object [] {FP. getname (), contents });
In. Close ();
} Catch (exception e ){
System. Err. println ("error" + E. tostring ());
}
}
}
3. Modify the run method of the action class
The content in the run method of the action class is what the Eclipse plug-in really wants to do.
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
* 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 previusly allocated.
* @ See iworkbenchwindowactiondelegate # dispose
*/
Public void dispose (){
}
/**
* We will cache window object in order
* Be Able To provide parent shell for the message dialog.
* @ See iworkbenchwindowactiondelegate # init
*/
Public void Init (iworkbenchwindow window ){
This. Window = window;
}
}
4. debugging
Start the axis server, and select Run as-> Run Time workbench from the eclipse run menu.
This will start another eclipse workbench. In this workbench, you will see a button added in the toolbar,
Click the button to call WebService and return the console results.