MyEclipse10 + Axis2 develop webservice, myeclipse10axis2

Source: Internet
Author: User

MyEclipse10 + Axis2 develop webservice, myeclipse10axis2
Recently, I was preparing to use Axis2 for WebService development. During this period, I encountered some pitfalls. I installed the latest Axis2 plug-in under MyEclipse10, I don't know whether it's a matter of character or whether the plug-in's compatibility is not very powerful. I can only use the earlier version of Axis2.

Axis2 plug-in: http://axis.apache.org/axis2/java/core/tools/index.html

1. download and install the Axis2 plug-in MyEclipse: (1) MyEclipse Axis2 plug-in
Http://archive.apache.org/dist/ws/axis2/tools/1_4_1/

Download the axis2-eclipse-codegen-wizard.zip and axis2-eclipse-service-archiver-wizard.zip

Http://archive.apache.org/dist/ws/axis2/1_5_1/
Download axis2-1.5.1-war.zip and axis2-1.5.1-bin.zip(2) decompress the plug-in ($ ECLIPSE_HOME indicates the myeclipse main directory you have installed)Unzip the above plug-in, copy the axis2.war file under the axis2-1.5.1-war to the tomcat \ webapps directory,Start tomcat Input Http: // localhost: 8080/axis2Open the main interface of axis2. If yes, the installation is successful;(3rd copy the extracted files of axis2-eclipse-codegen-wizard.zipand axis2-eclipse-service-archiver-wizard.zipIn the $ ECLIPSE_HOME \ MyEclipse 10 \ dropins directory, restart MyEclipse. In file> new> other, you can see Axis2 Wizards. At this point, the Axis2 plug-in has been installed successfully.(4) Try to generate a java source file using the wsdl file. An error may occur, An error occurred while completingprocess-java.lang.reflect.InvocationTargetExceptioN error. The solution is as follows: Setp1:Copy the "geronimo-stax-api_1.0_spec-1.0.1.jar" and "backport-util-concurrent-3.1.jar" from the Axis2 lib Library (you can download these two jar packages by yourself if not found) to the Axis2_Codegen_Wizard_1.3.0 lib directory, modify the plug-in under Axis2_Codegen_Wizard_1.3.0. xml file, add in <runtime><Library name = "library/geronimo-stax-api_1.0_spec-1.0.1.jar">
<Export name = "*"/>
</Library>
<Library name = "library/backport-util-concurrent-3.1.jar">
<Export name = "*"/>
</Library>Go to the plugin. xml file and change version = "1.3.0" to version = "1.4.0" to save it!
Step 2:Change Axis2_Codegen_Wizard_1.3.0 to Axis2_Codegen_Wizard_1.4.0.
Restart Myeclipse and use wsdl to generate the java source file to generate the java file. The plug-in is installed successfully!

Ii. Simple Example of Axis2 Webservice:1. Create a New Web Project Axis2Service and create User. java
<Span style = "font-size: 18px; font-style: normal;"> public class User implements Serializable {private static final long serialVersionUID =-8428746819403017248L; private int id; private String name; private int age; // The getter and setter methods are generated.} </span>
2. Create a service to publish UserService. java
<Span style = "font-size: 18px; font-style: normal;"> public class UserService {public String getGreetin (String name) {return "Welcome:" + name ;} public String addUser (User user) {if (null! = User) {return "hello" + user. getName () ;}return "user is null";} public User queryUser () {User user User = new user (); user. setId (1000120); user. setName ("Li Yifei"); user. setAge (27); return user;} public String addUsers (User [] users) {if (null! = Users) {return "Welcome:" + Arrays. toString (users);} return "users is null";} public User [] queryUsers () {User [] users = new User [2]; user user1 = new User (); user1.setId (1000120); user1.setName ("zhang fei"); user1.setAge (1000); User user2 = new User (); user2.setId (1000121 ); user2.setName ("zhao yun"); user2.setAge (995); users [0] = user1; users [1] = user2; return users ;}</span>
3. Publish a service(1) Right-click the project name Axis2Service-> New-> Other and select Axis2 Service Archiver,(2) package the compilation file, pointing to the location of the compiled service file, generally XXX \ WebRoot \ WEB-INF \ classes,Next-> select the skip WSDL, Next-> do not fill in NEXT-> select Generate the service xml automatically, NEXT->
For example, enter the full path of the UserService class and click load. The Method shown in the Method table below indicates that load is successful. click NEXT,
Enter the Output file location and click Finish, as shown in.(3) Right-click the Axis2Service project and refresh it. The UserService. aar file appears, for example:Put the UserService. aar file under % atat_home % webapps \ axis2 \ WEB-INF \ services.
Browser Input Http: // localhost: 8080/axis2/services/UserService? WsdlIf yes, the release is successful.4. Use MyEclipse's Web Service Client to generate Client call code(1) Axis2Client, a New Web Project, right-click new-> other-> Web Service Client in the Project, and select,Click NEXT> show
Click Next,
Enter the WSDL file location, for example, click Next,By default, click Next,Select Output path. Generally, select the client project directly, click Finish, and Refresh to Refresh the Axis2Client project generation. If the file is successfully generatedAdd the dependency package of the Axis2 client under the lib of the Axis2Client project, as shown in figureCreate a test class,
Package com. test; import com. axis2.service. userServiceStub; import com. axis2.service. userServiceStub. getGreetin; import com. axis2.service. userServiceStub. getGreetinResponse; public class TestUserSerivce {public static void main (String [] args) throws Exception {UserServiceStub stub = new UserServiceStub (); UserServiceStub. getGreetin getGreeting = new GetGreetin (); getGreeting. setName ("zhaoyun"); GetGreetinResponse gRes = stub. getGreetin (getGreeting); // the return value of the Receiving Method String getResult = gRes. get_return (); System. out. println (getResult );}}
Run the program and output Welcome: zhaoyun!
3. Other methods to generate the client java file: (1), enter the cmd command window, switch to the Axis2-1.5.1 \ bin directory, enterWsdl2java-uri http: // localhost: 8080/axis2/services/UserService? Wsdl-p com. axis2.clientOK, the code is generated under the Axis2-1.5.1 \ bin directory.(2) Compile bat to generate client code
set Axis_Lib=E:\myworkspace10\Axis2Client\WebRoot\WEB-INF\libset Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%   set Output_Path=D:\Axis2Clientset Package=com.axis2.client%Java_Cmd% org.apache.axis2.wsdl.WSDL2Java -o %Output_Path% -p %Package% -uri http://localhost:8080/axis2/services/UserService?wsdl  pause
E: \ myworkspace10 \ Axis2Client \ WebRoot \ WEB-INF \ lib is the jar package directory under the new client project,D: \ Axis2Client refers to the file directory of the generated code, and com. axis2.client refers to the package name of the generated code directory.

 

Run the compiled batch processing file (buildWebserviceClient. bat) to generate a java file under the specified directory.


























 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.