top of page

Jaxws-rt.jar: The Reference Implementation of JAX-WS 2.3.1



How to Download and Use jaxws-rt.jar




JAX-WS is a standardized API for creating and consuming SOAP web services in Java. In this article, we will learn how to download and use the jaxws-rt.jar file, which is the JAX-WS runtime bundle that contains the implementation classes and dependencies of the JAX-WS API.


What is jaxws-rt.jar?




Before we download and use the jaxws-rt.jar file, let's understand what it is and what it contains.




jaxws-rt.jar download




JAX-WS API and RI




JAX-WS stands for Java API for XML Web Services. It is a set of interfaces and annotations that define how to create and consume SOAP web services in Java. It is part of the standard Java platform since Java SE 6.


JAX-WS RI stands for JAX-WS Reference Implementation. It is an open source project that provides a complete and compliant implementation of the JAX-WS API. It also includes some extensions and tools for developing web services, such as wsimport, wsgen, wsdlc, etc.


JAX-WS Runtime Bundle




The jaxws-rt.jar file is the JAX-WS runtime bundle that contains the implementation classes and dependencies of the JAX-WS API and RI. It includes the following packages:


  • com.sun.xml.ws: The core package that contains the classes for creating and invoking web services, such as Service, Endpoint, Dispatch, etc.



  • com.sun.xml.ws.policy: The package that contains the classes for handling WS-Policy assertions, such as Policy, Assertion, etc.



  • com.sun.xml.ws.addressing: The package that contains the classes for supporting WS-Addressing, such as AddressingVersion, WSEndpointReference, etc.



  • com.sun.xml.ws.binding: The package that contains the classes for managing web service bindings, such as Binding, BindingProvider, SOAPBinding, etc.



  • com.sun.xml.ws.encoding: The package that contains the classes for encoding and decoding SOAP messages, such as Codec, ContentType, XMLHTTPBindingCodec, etc.



  • com.sun.xml.ws.message: The package that contains the classes for representing SOAP messages and attachments, such as Message, Header, AttachmentSet, etc.



  • com.sun.xml.ws.model: The package that contains the classes for modeling web service metadata, such as SEIModel, JavaMethod, ParameterBinding, etc.



  • com.sun.xml.ws.transport: The package that contains the classes for handling web service transport protocols, such as WSHTTPConnection, TransportPipeFactory, TransportTubeFactory, etc.



  • com.sun.xml.ws.util: The package that contains some utility classes for web service development, such as VersionUtil, NamespaceSupport, Pool, etc.



  • org.jvnet.ws.databinding: The package that contains some interfaces and annotations for data binding support, such as DatabindingFactory, DatabindingModeFeature, etc.



How to Download jaxws-rt.jar?




There are different ways to download the jaxws-rt.jar file. Here are some of them:


Using Maven




If you are using Maven as your build tool, you can add the following dependency to your pom.xml file:


<dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws -rt</artifactId> <version>3.0.0</version> </dependency>


This will download the jaxws-rt.jar file and its transitive dependencies from the Maven Central Repository.


Using Java2s




If you are not using Maven, you can download the jaxws-rt.jar file from the Java2s website. This website provides a collection of Java libraries and resources for various purposes. You can search for jaxws-rt.jar in the search box and download the latest version or any previous version you need.


How to download jaxws-rt.jar file for web services development


Jaxws-rt.jar download link from GitHub Pages


Jaxws-rt.jar Maven dependency and Gradle dependency


Jaxws-rt.jar source code and documentation


Jaxws-rt.jar version 2.3.0 and 2.3.1 features and bug fixes


Jaxws-rt.jar compatibility with Java versions and platforms


Jaxws-rt.jar usage examples and tutorials


Jaxws-rt.jar alternatives and comparisons


Jaxws-rt.jar license and terms of use


Jaxws-rt.jar issues and troubleshooting


How to install jaxws-rt.jar in Eclipse IDE


How to use jaxws-rt.jar with Spring Boot framework


How to create SOAP web services with jaxws-rt.jar


How to consume SOAP web services with jaxws-rt.jar


How to enable MTOM with jaxws-rt.jar


How to handle attachments with jaxws-rt.jar


How to implement WS-Security with jaxws-rt.jar


How to use WS-Policy with jaxws-rt.jar


How to use WS-Addressing with jaxws-rt.jar


How to use WS-MetadataExchange with jaxws-rt.jar


How to use WS-RM with jaxws-rt.jar


How to use WS-MEX with jaxws-rt.jar


How to use WS-SecureConversation with jaxws-rt.jar


How to use WS-Federation with jaxws-rt.jar


How to use WS-SecurityPolicy with jaxws-rt.jar


Using GitHub Pages




Another option to download the jaxws-rt.jar file is to use the GitHub Pages of the JAX-WS RI project. This project hosts the source code and releases of the JAX-WS RI. You can browse the releases page and download the jaxws-rt.jar file from the corresponding zip or tar.gz file.


How to Use jaxws-rt.jar?




Once you have downloaded the jaxws-rt.jar file, you can use it to create and consume SOAP web services in Java. Here are some steps to follow:


Creating a SOAP Web Service




To create a SOAP web service using JAX-WS, you need to do two things: define the service interface and implement the service class.


Bottom-Up Approach




The bottom-up approach is to start with the service class and use annotations to define the service interface. For example, suppose you want to create a simple calculator web service that can perform addition, subtraction, multiplication, and division operations. You can write the service class as follows:


import javax.jws.WebService; import javax.jws.WebMethod; import javax.jws.WebParam; @WebService public class CalculatorService @WebMethod public double add(@WebParam(name = "x") double x, @WebParam(name = "y") double y) return x + y; @WebMethod public double subtract(@WebParam(name = "x") double x, @WebParam(name = "y") double y) return x - y; @WebMethod public double multiply(@WebParam(name = "x") double x, @WebParam(name = "y") double y) return x * y; @WebMethod public double divide(@WebParam(name = "x") double x, @WebParam(name = "y") double y) return x / y;


The @WebService annotation indicates that this class is a web service endpoint. The @WebMethod annotation indicates that each method is a web service operation. The @WebParam annotation indicates the name of each parameter in the SOAP message.


To generate the service interface (also known as SEI or Service Endpoint Interface) and the WSDL (Web Service Description Language) file from this class, you can use the wsgen tool that comes with the jaxws-rt.jar file. For example, you can run the following command in your terminal:


wsgen -cp . -d output -keep CalculatorService


This will create a CalculatorService.class file in the output directory, along with a CalculatorService.wsdl file and a CalculatorServiceSEI.class file. The CalculatorServiceSEI.class file is the service interface that defines the methods and annotations of the web service. The CalculatorService.wsdl file is an XML document that describes the web service contract, such as the name, port, binding, operations, messages, etc.


Top-Down Approach




The top-down approach is to start with the WSDL file and use it to generate the service interface and class. For example, suppose you have a WSDL file that defines a calculator web service as follows:


<?xml version="1.0" encoding="UTF-8"?> <definitions name="CalculatorService" targetNamespace=" xmlns=" xmlns:soap=" xmlns:tns=" xmlns:xsd=" <types> <xsd:schema targetNamespace=" <xsd:element name="addRequest"> <xsd:complexType> <x sd:sequence> <xsd:element name="x" type="xsd:double"/> <xsd:element name="y" type="xsd:double"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="addResponse"> <xsd:complexType> <xsd:sequence> <xsd:element name="result" type="xsd:double"/> </xsd:sequence> </xsd:complexType> </xsd:element> <!-- Similar elements for subtract, multiply, and divide operations --> </xsd:schema> </types> <message name="addRequest"> <part name="parameters" element="tns:addRequest"/> </message> <message name="addResponse"> <part name="parameters" element="tns:addResponse"/> </message> <!-- Similar messages for subtract, multiply, and divide operations --> <portType name="CalculatorServiceSEI"> <operation name="add"> <input message="tns:addRequest"/> <output message="tns:addResponse"/> </operation> <!-- Similar operations for subtract, multiply, and divide operations --> </portType> <binding name="CalculatorServiceBinding" type="tns:CalculatorServiceSEI"> <soap:binding style="document" transport=" <operation name="add"> <soap:operation soapAction="" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" /> </output> </operation> <!-- Similar operations for subtract, multiply, and divide operations --> </binding> <service name="CalculatorService"> <port name="CalculatorServicePort" binding="tns:CalculatorServiceBinding"> <soap:address location=" </port> </service> </definitions>


To generate the service interface and class from this WSDL file, you can use the wsimport tool that comes with the jaxws-rt.jar file. For example, you can run the following command in your terminal:


wsimport -d output -keep CalculatorService.wsdl


This will create a CalculatorService.class file and a CalculatorServiceSEI.class file in the output directory. The CalculatorService.class file is the service class that extends the javax.xml.ws.Service class and provides methods to get the port of the web service. The CalculatorServiceSEI.class file is the service interface that defines the methods and annotations of the web service.


Consuming a SOAP Web Service




To consume a SOAP web service using JAX-WS, you need to do two things: generate the client stubs and invoke the service methods.


Generating Client Stubs




The client stubs are the classes that act as proxies for the web service. They hide the details of SOAP communication and allow you to invoke the web service methods as if they were local methods. To generate the client stubs, you need to have the WSDL file of the web service. You can use the wsimport tool to generate the client stubs from the WSDL file. For example, if you have the CalculatorService.wsdl file, you can run the following command in your terminal:


wsimport -d output -keep CalculatorService.wsdl


This will create a CalculatorService.class file and a CalculatorServiceSEI.class file in the output directory. The CalculatorService.class file is the service class that extends the javax.xml.ws.Service class and provides methods to get the port of the web service. The CalculatorServiceSEI.class file is the service interface that defines the methods and annotations of the web service.


Invoking Service Methods Invoking Service Methods




Once you have the client stubs, you can use them to invoke the web service methods. You need to create an instance of the service class and get the port of the web service. Then, you can call the methods of the port as if they were local methods. For example, if you want to use the calculator web service, you can write the following code:


import javax.xml.ws.WebServiceRef; public class CalculatorClient @WebServiceRef(wsdlLocation = "CalculatorService.wsdl") private static CalculatorService service; public static void main(String[] args) try // Get the port of the web service CalculatorServiceSEI port = service.getCalculatorServicePort(); // Invoke the web service methods double x = 10.0; double y = 5.0; double result = 0.0; result = port.add(x, y); System.out.println("Addition: " + x + " + " + y + " = " + result); result = port.subtract(x, y); System.out.println("Subtraction: " + x + " - " + y + " = " + result); result = port.multiply(x, y); System.out.println("Multiplication: " + x + " * " + y + " = " + result); result = port.divide(x, y); System.out.println("Division: " + x + " / " + y + " = " + result); catch (Exception e) e.printStackTrace();


This code will print the following output:


Addition: 10.0 + 5.0 = 15.0 Subtraction: 10.0 - 5.0 = 5.0 Multiplication: 10.0 * 5.0 = 50.0 Division: 10.0 / 5.0 = 2.0


Conclusion




In this article, we have learned how to download and use the jaxws-rt.jar file, which is the JAX-WS runtime bundle that contains the implementation classes and dependencies of the JAX-WS API and RI. We have also learned how to create and consume SOAP web services in Java using JAX-WS.


JAX-WS is a powerful and easy-to-use API for developing and consuming SOAP web services in Java. It provides a standard and portable way to create and invoke web services across different platforms and technologies.


FAQs




Q: What is SOAP?


  • A: SOAP stands for Simple Object Access Protocol. It is a protocol for exchanging structured and typed information between web service endpoints using XML.




Q: What is WSDL?


  • A: WSDL stands for Web Service Description Language. It is an XML document that describes the web service contract, such as the name, port, binding, operations, messages, etc.




Q: What is WS-Policy?


  • A: WS-Policy is a specification that defines a framework for expressing policies that apply to web services.




Q: What is WS-Addressing?


  • A: WS-Addressing is a specification that defines a standard way to identify and exchange information about web service endpoints.




Q: What is data binding?


  • A: Data binding is a process that converts XML data into Java objects and vice versa.




44f88ac181


61 views0 comments

Recent Posts

See All
bottom of page