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

GWT应用集成gwt-servlet编译报错求助

GWT编译报错排查与解决

问题详情

按照教程完成操作后,GWT编译时出现错误,已排查依赖库和Servlet声明未发现问题,相关信息如下:


核心代码

GwtRpcService.java(客户端/共享接口)

@RemoteServiceRelativePath("gwtRpcService")
public interface GwtRpcService extends RemoteService {
    BaseRpcResult sendToPrint(EntityProxy model);
}

GwtRpcServiceAsync.java(客户端异步接口)

public interface GwtRpcServiceAsync {
    void sendToPrint(EntityProxy data, AsyncCallback<BaseRpcResult> async);
}

GwtRpcServiceImpl.java(服务端实现类)

@Service
public class GwtRpcServiceImpl extends RemoteServiceServlet implements GwtRpcService {
    @Autowired
    private PrintService printService;

    @Override
    public BaseRpcResult sendToPrint(EntityProxy entityProxy) throws IllegalArgumentException {
        // 业务逻辑代码
    }
}

编译错误日志

[ERROR] Line 38: No source code is available for type <project_path>.gwt.server.GwtRpcServiceImpl; did you forget to inherit a required module?
[ERROR] Unable to find type '<project_path>.gwt.client.AppBundle'
[ERROR] Hint: Previous compiler errors may have made this type unavailable
[ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly

配置文件

Main.gwt.xml

<module rename-to="gwt">

    <source path='client'/>
    <source path='shared'/>

    <inherits name='com.google.gwt.user.User'/>
    <inherits name='com.google.gwt.logging.Logging'/>
    <inherits name="com.google.gwt.uibinder.UiBinder"/>
    <inherits name="com.google.web.bindery.requestfactory.RequestFactory"/>
    <inherits name="org.hibernate.validator.HibernateValidator" />
</module>

web.xml

<servlet>
    <servlet-name>gwtRpcService</servlet-name>
    <servlet-class> <project_path>.gwt.server.GwtRpcServiceImpl </servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>gwtRpcService</servlet-name>
    <url-pattern>/main/gwtRpc</url-pattern>
</servlet-mapping>

pom.xml

<dependency>
     <groupId>com.google.gwt</groupId>
     <artifactId>gwt-servlet</artifactId>
     <version>${com.google.gwt.version}</version> <!-- 版本2.6.1 -->
</dependency>

解决办法

1. 修复GwtRpcServiceImpl找不到的错误

GWT编译器仅处理<source>标签指定的client和shared包代码,server包属于服务端代码,绝对不能被客户端代码直接引用。

  • 定位客户端代码第38行,删除对GwtRpcServiceImpl的直接引用
  • 客户端获取服务实例必须通过GWT.create()方法:
    GwtRpcService rpcService = GWT.create(GwtRpcService.class);
    ((ServiceDefTarget) rpcService).setServiceEntryPoint(GWT.getModuleBaseURL() + "gwtRpcService");
    

2. 解决AppBundle找不到的问题

  • 确认<project_path>.gwt.client.AppBundle类存在,检查包路径、类名拼写是否正确
  • 若AppBundle是UiBinder资源包,确认类本身无语法错误(之前的编译错误会导致类无法被识别)
  • 验证UiBinder模块继承是否生效:确保gwt-user依赖已添加(见下文)

3. 修正服务路径不匹配问题

你的@RemoteServiceRelativePath注解值为gwtRpcService,但web.xml中servlet-mapping的url-pattern是/main/gwtRpc,两者必须一致:

  • 方案一:修改注解为@RemoteServiceRelativePath("main/gwtRpc")
  • 方案二:修改web.xml的url-pattern为/gwt/gwtRpcService(因module rename-to为gwt,默认前缀为/gwt)

4. 补充缺失的GWT依赖

pom.xml中缺少gwt-user依赖,这是GWT编译客户端代码必需的,添加以下配置:

<dependency>
    <groupId>com.google.gwt</groupId>
    <artifactId>gwt-user</artifactId>
    <version>${com.google.gwt.version}</version>
    <scope>provided</scope>
</dependency>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 13:54:54