将Java包添加到GWT [英] Adding Java packages to GWT

查看:190
本文介绍了将Java包添加到GWT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过搜索,但无法想出如何将自己的包添加到GWT项目的定义方式。



我的树结构看起来像这:

  -com.mycompany 
- 公共
MyApplication.html
MyApplication.gwt .xml


-com.mycompany.client
MyApp.java

-com.mycompany.gui
TableLayout.java

我见过的答案是添加相对于gwt.xml根目录的包文件,如下所示:

 < module> 
<继承了name =com.google.gwt.user.User/>
< entry-point class =com.mycompany.client.MyApp/>
< source path =client/>
< source path =gui/>
< / module>

然后抱怨:

 无法找到类型'com.technicon.client.MyApp'
提示:以前的编译器错误可能导致此类型不可用
提示:检查模块的继承链;它可能不是继承所需的模块或模块可能没有正确添加其源路径条目

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

解决方案

您可以摆脱两条源路径行,因为默认情况下,GWT将会获取任何与root相关的东西,以及像客户端软件包那样的东西。您还需要将您的gui软件包移入您的客户端软件包,因此它会变成:

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


-com.mycompany.client
MyApp.java

-com.mycompany.client.gui
TableLayout.java


< module>
<继承了name =com.google.gwt.user.User/>
< entry-point class =com.mycompany.client.MyApp/>
< / module>

假设您的MyApp.java是一个实际的入口点,那么这应该工作得很好。



另外需要注意的是,你不能使用不属于GWT JRE仿真库的Java类,如果你这样做,你的项目将不会编译。尽管如此,你应该得到非常具体的错误。例如,如果不是模拟的,你不能使用像java.math.BigDecimal这样的库类。虽然您创建的所有类都可以使用。


I've tried searching but couldn't come up with a defined way on how to add your own packages to a GWT project.

My tree structure looks like this:

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


-com.mycompany.client
  MyApp.java

-com.mycompany.gui
  TableLayout.java

The answer I've seen out there says to add the packages relative to the root directory of the gwt.xml file, like so:

<module>
  <inherits name="com.google.gwt.user.User" />
  <entry-point class="com.mycompany.client.MyApp" />
  <source path="client" />
  <source path="gui" />
</module>

It then complains:

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

Can anyone tell me what I'm doing wrong and how to fix this?

解决方案

You can get rid of the two source path lines, because by default GWT will pick up anything that is relative to the root, and in the client package like you have. You also need to move your gui package into your client package, so it would become:

-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>

Assuming your MyApp.java is an actual EntryPoint, then this should work just fine.

One other thing to note is that you cannot use java classes that are not part of the GWT JRE Emulation library, and your project won't compile if you do. You should get very specific errors about this though. For example you cannot use library classes like java.math.BigDecimal, if they are not emulated. All of your own classes you create can be used though.

这篇关于将Java包添加到GWT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆