【问题标题】:How to include custom classes in GWT如何在 GWT 中包含自定义类
【发布时间】:2015-04-14 14:13:24
【问题描述】:

我正在尝试将我自己的包包含在 GWT 包中。如果我尝试在 GWT 应用程序中使用我自己的自定义包/类中的 Java 类,我会收到错误 “该类型没有可用的源代码。您是否忘记继承所需的模块” 而使用 Maven 构建。

我尝试了以下解决方案来解决上述问题:

  1. 我继承了gwt.xml中的自定义包
  2. 我在 GWT maven 应用程序的pom.xml 中包含了自定义包
  3. 在存储库中安装了 jar

但我仍然收到上述错误。

注意:我没有在 Eclipse 中仅在命令行 maven 构建期间收到此错误。

如何使用 maven 在 GWT 包中包含我自己的包?

wmc.gwt.xml

?xml version="1.0" encoding="UTF-8"?>
<module rename-to='wmc'>

  <!-- Inherit the core Web Toolkit stuff.                        -->
  <inherits name='com.google.gwt.user.User'/>


  <!-- Inherit the default GWT style sheet.  You can change       -->
  <!-- the theme of your GWT application by uncommenting          -->
  <!-- any one of the following lines.                            -->
  <inherits name='com.google.gwt.user.theme.clean.Clean'/>
  <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
  <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
  <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>     -->
  <inherits name="com.smartgwtpro.SmartGwtProNoTheme" />
  <inherits name="com.smartgwtpro.tools.Tools" />

  <inherits name="com.smartgwt.SmartGwtNoTheme"/>    
  <inherits name="com.smartclient.theme.enterprise.Enterprise"/>
  <inherits name="com.smartclient.theme.enterprise.EnterpriseResources"/>

  <inherits name='com.extjs.gxt.ui.GXT'/>
  <inherits name='com.googlecode.gchart.GChart'/>
  <inherits name='pl.balon.gwt.diagrams.Diagrams'/>
  <inherits name='com.google.gwt.visualization.Visualization'/>
  <inherits name='com.allen_sauer.gwt.dnd.gwt-dnd'/>

   <!-- inherit the customized package for accessing the method of that bundle -->
  <inherits name='com.bf.service.management'/>

  <!-- Specify the app entry point class.                         -->
  <entry-point class='com.isoft.web.viaductWebConsole.client.MonitorConsole'/>

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

上面提到的是 gwt.xml ,你会在其中找到 &lt;inherits name='com.bf.service.management'/&gt; - 这是我需要在 GWT 应用程序中使用的自定义包,但是当我尝试构建 GWT 代码时,我得到了 “未能执行目标 org.codehaus.mojo:gwt-maven-plugin:2.5.1 : compile on project wmc: GWT Module com.bf.service.management not found in project sources or resources”

【问题讨论】:

  • 你是在创建两个不同的maven项目还是在一个包中维护
  • 嗨 mohammed 我只是维护一个包并通过 maven 构建该包。作为参考,我已经用 gwt.xml 文件更新了主要问题部分。
  • 可能与您的自定义包有关?
  • 不,我的感觉是 GWT 编译器无法识别我的自定义包的方法。即使我在其他一些包中使用过这种自定义包方法,它也可以正常工作。如果我在 GWT 应用程序中使用它,只会出现问题
  • 也许您正在使用 GWT 无法编译的 Java 的某些功能?查看 JRE 白名单:gwtproject.org/doc/latest/RefJreEmulation.html(对不起,我无法提供更多帮助)

标签: maven gwt


【解决方案1】:

对我来说,只有在以下情况下才会发生这种情况:

  1. 您没有在我的project.gwt.xml 文件中放入正确的inherits 语句。

  2. inherits 语句的顺序错误。试着把它放在列表的前面。

只要你有正确的inherits 语句和你的pom.xml 中的正确依赖项,它应该可以工作。试着玩一下。

【讨论】:

  • 嗨,我继承了我在 GWT 应用程序 ingwt.xml 文件中尝试使用的自定义包,并在 pom.xml 中添加了依赖项。供您参考,我在主要问题部分添加了 gwt.xml 文件
  • 尝试将&lt;inherits name='com.bf.service.management'/&gt; 放在&lt;inherits name='com.google.gwt.user.User'/&gt; 行的下方?更改顺序通常对我有用。
  • 好的,我会试试的。还有一个问题是如何在 gwt 类/包中打印消息是 GWT 应用程序是否支持 System.out.println?
  • 我什至尝试重新排序 com.google.gwt.user.User 下的继承标签,但它显示与在 gwt 中找不到 com.bf.service.management 相同的错误
  • 是的,System.out 可以正常工作,但从长远来看,您应该考虑使用gwt-log。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-12
  • 2015-06-01
  • 2017-03-18
  • 2022-01-22
  • 2011-03-04
  • 2017-11-17
  • 1970-01-01
相关资源
最近更新 更多