如何在无默认JAX-WS栈的Payara Micro中提供SOAP接口?
Great question! Since Payara Micro is built to stay lightweight, it doesn’t include the JAX-WS stack out of the box. But there are several reliable ways to add SOAP support to your application—here are the most practical approaches:
1. Use Metro (GlassFish’s Native JAX-WS Implementation)
Metro is the same JAX-WS stack used in Payara Server Full, so it’s fully compatible with Payara Micro. Here’s how to set it up:
Add Metro dependencies to your project:
If you’re using Maven, include these in yourpom.xml:<dependencies> <!-- JAX-WS API --> <dependency> <groupId>javax.xml.ws</groupId> <artifactId>jaxws-api</artifactId> <version>2.3.1</version> <scope>provided</scope> </dependency> <!-- Metro runtime --> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-rt</artifactId> <version>2.3.5</version> <scope>runtime</scope> </dependency> <!-- Metro Servlet integration --> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-servlet</artifactId> <version>2.3.5</version> <scope>runtime</scope> </dependency> </dependencies>Annotate your SOAP service:
Create your service class with the standard@WebServiceannotation:@WebService public class HelloSoapService { @WebMethod public String sayHello(String name) { return "Hello, " + name + "!"; } }Register the service:
Let Metro auto-scan for services by adding asun-jaxws.xmlfile inWEB-INF:<?xml version="1.0" encoding="UTF-8"?> <endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0"> <endpoint name="HelloSoapService" implementation="com.yourpackage.HelloSoapService" url-pattern="/hello-soap"/> </endpoints>Package and run:
Bundle your app as a WAR or executable JAR with Payara Micro embedded. When you start Payara Micro, it will pick up the Metro runtime and deploy your SOAP endpoint.
2. Use Apache CXF
Apache CXF is another popular JAX-WS implementation that works seamlessly with Payara Micro. Here’s the setup:
Add CXF dependencies:
In yourpom.xml:<dependencies> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>3.6.2</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>3.6.2</version> </dependency> </dependencies>Configure CXF Servlet:
Register the CXF servlet using Java-based configuration:@Configuration public class CxfConfig { @Bean public ServletRegistrationBean<CXFServlet> cxfServlet() { ServletRegistrationBean<CXFServlet> servlet = new ServletRegistrationBean<>(new CXFServlet(), "/soap/*"); servlet.setLoadOnStartup(1); return servlet; } @Bean public Endpoint helloEndpoint() { EndpointImpl endpoint = new EndpointImpl(new HelloSoapService()); endpoint.publish("/hello"); return endpoint; } }Run your app:
Package and deploy to Payara Micro as usual. Your SOAP endpoint will be available athttp://localhost:8080/soap/hello.
3. Bundle Payara Full’s JAX-WS Modules (Advanced)
If you want to use the exact same JAX-WS stack as Payara Server Full, you can bundle the required modules with Payara Micro:
Identify required modules:
Key modules includejavax.ws.rs.api,com.sun.xml.ws.jaxws-rt, andcom.sun.xml.ws.jaxws-api.Start Payara Micro with modules added:
Use the--addModuleparameter when launching:java -jar payara-micro.jar --addModule javax.ws.rs.api --addModule com.sun.xml.ws.jaxws-rt --addModule com.sun.xml.ws.jaxws-api deploy your-app.warNote: This requires access to Payara Server Full’s module JARs and version compatibility with your Payara Micro build.
Key Tips
- Avoid Dependency Conflicts: Don’t include both Metro and CXF in the same project—stick to one implementation.
- Uber-Jar Packaging: If building an executable JAR, ensure all JAX-WS runtime dependencies are included in the final bundle.
- Test Thoroughly: Use tools like SoapUI or curl to validate your SOAP endpoint works as expected.
内容的提问来源于stack exchange,提问作者peez80

