You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Glassfish6 WAR模块含@WebService却无法以webservices引擎启动

解决GlassFish6 WAR部署中WebService引擎随机不识别的问题
  • 显式配置WebService部署描述符
    手动创建WEB-INF/webservices.xml,明确声明SOAP服务的接口和实现类,避免依赖GlassFish的自动扫描。示例配置:

    <?xml version="1.0" encoding="UTF-8"?>
    <webservices xmlns="http://java.sun.com/xml/ns/javaee" version="1.4">
        <webservice-description>
            <webservice-description-name>YourSoapService</webservice-description-name>
            <port-component>
                <port-component-name>YourSoapPort</port-component-name>
                <service-endpoint-interface>com.yourpackage.YourSoapServiceInterface</service-endpoint-interface>
                <service-impl-bean>
                    <ejb-link>YourSoapServiceImpl</ejb-link>
                </service-impl-bean>
            </port-component>
        </webservice-description>
    </webservices>
    

    同时确保WEB-INF/ejb-jar.xml正确关联EJB与WebService,消除扫描歧义。

  • 调整Maven WAR插件打包配置
    在pom.xml的maven-war-plugin中,强制指定WebService相关资源的打包路径,防止文件遗漏:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.3.2</version>
        <configuration>
            <webResources>
                <resource>
                    <directory>src/main/resources/META-INF</directory>
                    <targetPath>WEB-INF</targetPath>
                    <includes>
                        <include>webservices.xml</include>
                        <include>wsdl/**</include>
                    </includes>
                </resource>
            </webResources>
        </configuration>
    </plugin>
    
  • 禁用GlassFish延迟加载/扫描优化
    登录GlassFish管理控制台,进入服务器配置的Applications -> Deployment Settings,关闭Lazy Deployment选项;或者直接修改domain.xml添加JVM参数:

    <java-config>
        <jvm-options>-Dcom.sun.enterprise.deployment.lazy=false</jvm-options>
    </java-config>
    

    这类优化可能导致WebService类未被及时扫描,延迟数小时后才触发识别。

  • 明确EJB与WebService的双重身份
    在SOAP服务实现类上同时标注@Stateless(或对应EJB注解)和@WebService,确保GlassFish同时识别其EJB和WebService属性:

    @Stateless
    @WebService(endpointInterface = "com.yourpackage.YourSoapServiceInterface")
    public class YourSoapServiceImpl implements YourSoapServiceInterface {
        // 业务方法实现
    }
    
  • 清理GlassFish缓存与临时文件
    每次部署前手动删除GlassFish域目录下的generated、cache、tmp文件夹,避免旧部署残留干扰扫描。也可以通过Maven插件自动执行清理:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
            <execution>
                <id>clean-glassfish-cache</id>
                <phase>pre-deploy</phase>
                <goals>
                    <goal>exec</goal>
                </goals>
                <configuration>
                    <executable>rm</executable>
                    <arguments>
                        <argument>-rf</argument>
                        <argument>/path/to/glassfish/domains/domain1/generated</argument>
                        <argument>/path/to/glassfish/domains/domain1/cache</argument>
                        <argument>/path/to/glassfish/domains/domain1/tmp</argument>
                    </arguments>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

内容的提问来源于stack exchange,提问作者krazytoukan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 12:00:27