将Java包添加到GWT

Org*_*cat 10 java gwt packages

我已经尝试过搜索,但是无法想出如何将自己的包添加到GWT项目中.

我的树结构如下所示:

-com.mycompany
  -public
    MyApplication.html
  MyApplication.gwt.xml


-com.mycompany.client
  MyApp.java

-com.mycompany.gui
  TableLayout.java
Run Code Online (Sandbox Code Playgroud)

我在那里看到的答案是说相对于gwt.xml文件的根目录添加包,如下所示:

<module>
  <inherits name="com.google.gwt.user.User" />
  <entry-point class="com.mycompany.client.MyApp" />
  <source path="client" />
  <source path="gui" />
</module>
Run Code Online (Sandbox Code Playgroud)

然后抱怨:

Unable to find type 'com.technicon.client.MyApp'
   Hint: Previous compiler errors may have made this type unavailable
   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
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我我做错了什么以及如何解决这个问题?

sam*_*miq 9

尽管如此,正如@rustyshelf所指出的那样,gwt将client.*自动转换所有内容,有时候你会希望将东西保存在客户端软件包之外(在多个项目中重用它们可能就是其中之一)并且为此解决方案仍然在于使用该source元素向流程中添加其他包.

现在有一个技巧,你必须决定是否要移动gwt.xml配置文件或是否需要创建一个新文件.

特别是对于你的情况(两个包共享包中的根,com.mycompany)你可以将<project_name>.gwt.xml文件移动到最常见的包,只需添加新包作为源(并保持在<source path="client"/>那里)因此使您的文件看起来像:

<source path="client"/>
<source path="gui"/>
Run Code Online (Sandbox Code Playgroud)

另一方面,如果包不共享任何根,只需创建一个*.gwt.xml只包含源元素的新文件,并将其放在父包中,添加到要添加的子包中,即:

<module>
   <source path=""/>
</module>
Run Code Online (Sandbox Code Playgroud)

请注意,如果您需要对嵌套子包进行编译访问,请使用/类似的方法将它们分开"admin/client"

希望这有助于您回到正轨并以最佳方式组织代码.


rus*_*elf 5

您可以摆脱两个源路径行,因为默认情况下,GWT会选择与根相关的任何内容,并在客户端包中提取.您还需要将gui包移动到您的客户端包中,因此它将变为:

-com.mycompany
  -public
    MyApplication.html
  MyApplication.gwt.xml


-com.mycompany.client
  MyApp.java

-com.mycompany.client.gui
  TableLayout.java


<module>
  <inherits name="com.google.gwt.user.User" />
  <entry-point class="com.mycompany.client.MyApp" />
</module>
Run Code Online (Sandbox Code Playgroud)

假设您的MyApp.java是一个真正的EntryPoint,那么这应该可以正常工作.

另外需要注意的是,您不能使用不属于GWT JRE Emulation库的java类,如果您这样做,您的项目将无法编译.你应该得到关于这个的非常具体的错误.例如,如果未模拟它们,则不能使用java.math.BigDecimal等库类.您创建的所有类都可以使用.