GWT 小部件库 - 源不可翻译

GWT Widget Library - Source not translatable

我正在尝试创建一个 GWT 小部件模块。现在,它只有一个小部件,仅用于测试。我尝试将此模块包含在不同的项目中,我得到:

No source code is available for type com.company.gwt.client.components.VerticalDiv; did you forget to inherit a required module?

在我的主项目中 module.gwt.xml 我有:

<module>
    <!-- Google Modules -->
    <inherits name="com.google.gwt.user.User" />
    <inherits name="com.googlecode.gwt.crypto.Crypto" />

    <inherits name="com.company.gwt.GWT_Library" />

    <entry-point class="com.company.app.client.App" />

    <source path="" />

    <resource path="resources" />

    <!-- Only support recent browsers -->
    <set-property name="user.agent" value="ie10,gecko1_8,safari" />
</module>

GWT_Library xml 位于 com.company.gwt 中,看起来像这样:

<module>       
    <inherits name="com.google.gwt.user.User" />
    <inherits name="com.google.gwt.resources.Resources" />

    <source path="client" />
    <resource path="client" />
</module>

项目结构:

.
+-- pom.xml
+-- src
|   +-- main
|       +-- java
|           +-- com
|               +-- company
|                   +-- gwt
|                       +-- client
|                           +-- components
|                               +-- VerticalDiv.java
|       +-- resources
|           +-- com
|               +-- company
|                   +-- gwt
|                       +-- GWT_Library.gwt.xml
|                       +-- client

我知道主项目包括它,因为如果我更改 module.gwt.xml 中的 inherits 行,它会给我一个无法找到的错误它。

这里是 VerticalDiv class:

package com.company.gwt.client.components;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.FlowPanel;

public class VerticalDiv extends FlowPanel implements HasClickHandlers
{
    public VerticalDiv()
    {
    }

    @Override
    public HandlerRegistration addClickHandler(ClickHandler handler)
    {
        return this.addDomHandler(handler, ClickEvent.getType());
    }
}

这个 class 曾经在我的主项目中使用过,在那里工作得很好。我有另一个名为 "Shared" 的模块,它也能正常工作。但是,这个包没有任何可以在 UiBinder 中使用的东西。我认为这可能是不同之处。 VerticalDiv class 在 UI 活页夹中被引用,像这样:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
             xmlns:g='urn:import:com.google.gwt.user.client.ui'
             xmlns:e="urn:import:com.company.app.client.widgets"
             xmlns:c="urn:import:com.company.gwt.client.components"
>
    <ui:style>
        <!-- styling -->
    </ui:style>

    <g:HTMLPanel>
        <c:VerticalDiv>
            <e:LinkButton ui:field="viewAll" text="All Notifications"></e:LinkButton>
        </c:VerticalDiv>
    </g:HTMLPanel>
</ui:UiBinder>

如您所见,我还使用了主项目中的一个小部件,它以这种方式正常工作。

为了让我的模块小部件在 UiBinder 文件中可用,我是否缺少某些东西?

您需要为 "components" 模块创建描述符,例如MyComponents.gwt.xml,在您的 com.company.gwt 目录中。然后你需要在你的主模块中继承它 xml:

<inherits name="com.company.gwt.MyComponents"/>

这个MyComponents.gwt.xml可以非常简单(取决于它使用的GWT模块):

<module>

  <inherits name='com.google.gwt.user.User'/>
  <inherits name='com.google.gwt.i18n.I18N'/>
  <inherits name="com.google.gwt.resources.Resources"/>

  <!-- Specify the paths for translatable code                    -->
  <source path='client'/>
  <source path='shared'/>

</module>

事实证明这个错误比预期的更准确...

我正在使用 maven 进行构建,所以要完成这项工作,我必须:

  1. 生成了源 jar。所以在小部件模块中 pom.xml:
<plugin>
    <artifactId>maven-source-plugin</artifactId>
    <version>3.0.1</version>
    <executions>
        <execution>
            <id>attach-sources</id>
            <phase>package</phase>
            <goals>
                <goal>jar-no-fork</goal>
            </goals>
        </execution>
    </executions>
</plugin>
  1. 在我的主项目中包含源代码pom.xml:
<dependency>
    <artifactId>gwt-library</artifactId>
    <groupId>com.company.gwt</groupId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
    <artifactId>gwt-library</artifactId>
    <groupId>com.company.gwt</groupId>
    <version>1.0.0-SNAPSHOT</version>
    <classifier>sources</classifier>
</dependency>

所以,错误是正确的。确实没有源码。