GWT Widget Library-源代码不可翻译



我正在尝试创建一个GWT小部件模块。现在,它只有一个小部件,只用于测试。我试着把这个模块包括在一个不同的项目中,我得到了:

No source code is available for type com.company.gwt.client.components.VerticalDiv; did you forget to inherit a required 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中的herits行,它会给我一个找不到它的错误。

这是VerticalDiv类:

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());
}
}

这门课曾经是我的主要项目,在那里效果很好。我有另一个名为"共享"的模块,它也很好用。不过,此程序包没有任何可以在UiBinder中使用的内容。我认为这可能就是区别。VerticalDiv类在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文件中是否缺少可用的东西?

您需要在com.company.gwt目录中为"组件"模块创建一个描述符,例如MyComponents.gwt.xml。然后您需要在主模块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>

所以,这个错误是正确的。源代码确实不可用。

最新更新