JAKARTA XML Web Services API in the Java class library

JAKARTA XML Web Services API in the Java class library Jakarta XML Web Services (JAX-WS) is a set of Java libraries for the development of SOAP standard Web Services.This article will introduce how to use Jakarta XML Web Services API to build and call Web Services. First, make sure that JDK and any necessary construction tools (such as Apache Maven) have been installed in order to use JAX-WS. 1. Create web service First, create a Java class containing Web Services.Use the@webService` annotation to mark it as web service and use the method to use the `@webmethod` annotation mark: import javax.jws.WebService; import javax.jws.WebMethod; @WebService public class MyWebService { @WebMethod public String sayHello(String name) { return "Hello, " + name + "!"; } } 2. Release web service Before publishing Web Services, you need to configure a Web Services container.You can choose to use built -in containers or external containers (such as Apache Tomcat).Here, we use built -in containers to demonstrate.In the `Main` method, use the` Endpoint.publish` method to publish web service: import javax.xml.ws.Endpoint; public class MyWebServicePublisher { public static void main(String[] args) { String url = "http://localhost:8080/myWebService"; Endpoint.publish(url, new MyWebService()); System.out.println ("Web Service has been released:" + url); } } 3. Build a client Now we need to build a client to call Web Service.You can use the client code to use the `wsimport` tool to generate the client code from WSDL (Web Services Description Language) file.Suppose WSDL file is located in `http:// localhost: 8080/Mywebservice? WSDL`, execute the following command: wsimport -s src -d bin http://localhost:8080/myWebService?wsdl The command will generate client code and place it in the `src` directory. 4. Use the client to call Web Service Using the generated client code, we can easily call Web Service.The following is an example: import com.example.MyWebService; import com.example.MyWebServiceService; public class MyWebServiceClient { public static void main(String[] args) { MyWebServiceService service = new MyWebServiceService(); MyWebService port = service.getMyWebServicePort(); String response = port.sayHello("World"); System.out.println(response); } } The above code will use the client to call the `Sayhello` method of Web Service and print the result to the console. The above is a brief guide to build and call Web Services with Jakarta XML Web Services API.We can further expand and customize the Web Service's functions according to actual needs.I hope this article can help you get started with JAX-WS. Please note that in order to make the code more concise, omittobed abnormal processing and other details.In actual development, it should be appropriately dealt with abnormalities, and more configuration and parameter settings should be performed as needed.