GlassFish部署JAX-WS服务异常:无法识别服务并生成WSDL/端点
Hey there! Let's break down why your web service isn't being recognized by GlassFish and walk through the fixes step by step. Here are the most common issues to check:
Java EE web services (JAX-WS) rely on annotations to signal the server to expose them as endpoints. Double-check your service class has the right tags:
- If you're using a service endpoint interface (SEI), add
@WebServiceto the interface. - For the implementation class, use
@WebService(endpointInterface = "your.package.YourSEIName")(to link to the SEI) or just@WebServiceif you're defining the service directly in the class. - Quick example:
package com.yourcompany; import javax.jws.WebService; @WebService public class GreetingService { public String greet(String name) { return "Hi " + name + "!"; } }
web.xml Configuration Your web.xml might be missing the servlet mapping that lets GlassFish handle web service requests. Add this section to your deployment descriptor:
<servlet> <servlet-name>GreetingService</servlet-name> <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>GreetingService</servlet-name> <url-pattern>/GreetingService</url-pattern> </servlet-mapping>
Also, make sure you have the correct Java EE namespace declared at the top of web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
If your dynamic web project isn't configured to use Java EE (e.g., it's a plain Servlet project), you might be missing the required JAX-WS jars. GlassFish provides these, but sometimes Eclipse doesn't pull them into your build path automatically:
- Right-click your project → Properties → Targeted Runtimes → Ensure GlassFish is checked. This should add all necessary Java EE libraries.
- If that fails, manually copy
jaxws-api.jarandjaxws-rt.jarfrom your GlassFishmodulesfolder into your project'sWEB-INF/libdirectory.
When generating your WAR file, confirm all essential files are included:
- Compiled service class files in
WEB-INF/classes. - Any required libraries in
WEB-INF/lib. - The correct
web.xmlin theWEB-INFfolder. - If you're using an SEI, the interface class must also be present in
WEB-INF/classes.
Even if deployment says "success", there might be hidden warnings or errors preventing the web service from registering. Open the GlassFish logs (located at glassfish/domains/domain1/logs/server.log) and search for keywords like "JAX-WS", "endpoint", or "WSDL" to spot issues.
When creating your dynamic web project, make sure you:
- Selected Dynamic Web Project and chose GlassFish as the target runtime.
- Enabled the correct project facets: Java (matching your GlassFish version) and Dynamic Web Module. For Java EE 6+, you don't need to manually enable web service facets if using annotations, but double-check the JAX-WS facet is enabled if it appears in the list.
Once you fix these, redeploy your WAR to GlassFish. You should be able to access the WSDL at http://localhost:8080/YourProjectName/GreetingService?wsdl (replace with your actual project and service names).
内容的提问来源于stack exchange,提问作者ronak_11

