简体   繁体   English

GWT找不到自定义类?

[英]GWT not finding custom classes?

I've been all over the Internet and can't seem to get a straight answer, just looking to clarify something. 我到过互联网,似乎无法获得直接的答案,只是想澄清一些事情。

I need my web app to return from the server an ArrayList. 我需要Web应用程序才能从服务器返回ArrayList。 Por is a custom class that implements Serializable and follows all the rules I've been able to find about being serializable for GWT. Por是一个实现Serializable的自定义类,它遵循我为GWT可序列化所能找到的所有规则。

My gwt.xml file (in com.pbot package) has: 我的gwt.xml文件(在com.pbot程序包中)具有:

<source path='com.pbot'/>

and all my custom classes (including Por) are in that same com.pbot package. 我所有的自定义类(包括Por)都在同一个com.pbot程序包中。 But I'm still getting the "No source code is available for type com.pbot.Por; did you forget to inherit a required module?" 但是我仍然收到“ com.pbot.Por类型没有可用的源代码;您忘记了继承必需的模块吗?” message. 信息。 Do I need to make a second gwt.xml with com.pbot as source and import it? 我是否需要使用com.pbot作为源创建第二个gwt.xml并将其导入? If so, how do I do that and where do I put it? 如果是这样,我该怎么办?我应该放在哪里? If not, what am I missing? 如果没有,我想念什么?

Entire gwt.xml code below: 完整的gwt.xml代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<!--
  When updating your version of GWT, you should also update this DTD reference,
  so that your app can take advantage of the latest GWT module capabilities.
-->
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN"
  "http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd">
<module rename-to='pbot'>
  <!-- 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'/>     -->

  <!-- Other module inherits                                      -->

  <!-- Specify the app entry point class.                         -->
<entry-point class='com.pbot.client.Pbot'/>
  <!-- Specify the paths for translatable code                    -->
  <source path='client'/>
  <source path='shared'/>
  <source path='com.pbot'/>

</module>

Add

<source path=''/>

instead of 代替

<source path='com.pbot'/>

But still I think you should put your custom classes into correct packages, so in case of Por into shared package (beacause you're using Por on client side and also on server side). 但是我仍然认为您应该将自定义类放入正确的包中,因此,如果将Por放入共享包中(因为您在客户端和服务器端都使用Por)。 However, I don't know the circumstances (if you can do that) so that's just an advice. 但是,我不知道情况如何(如果可以的话),所以这只是一个建议。

The reason behind that is that with this you are providing your whole package com.pkg to be translated into JavaScript and soon or later you will get into trouble with this attitude. 其背后的原因是,通过此操作,您将提供整个软件包com.pkg并将其翻译成JavaScript,并且您迟早会以这种态度遇到麻烦。 So best thing is - put your custom classes into client or shared package if it's possible and then remove 所以最好的办法是-如果可能,将自定义类放入客户端或共享包中,然后删除

<source path=''/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM