简体   繁体   English

如何将bean从外部库共享到GWT客户端?

[英]How can share bean from external library to GWT client?

I have a question about share the java bean in library to gwt client I know bean share between GWT client and server usually put into package domain.shared. 我有一个关于将库中的java bean共享到gwt客户端的问题我知道GWT客户端和服务器之间的bean共享通常放入包domain.shared。

However, how can I make use of existing bean from external jar library on GWT client? 但是,如何在GWT客户端上使用外部jar库中的现有bean?

Because I always got this message. 因为我总是收到这条消息。 No source code is available for type xxxx.xxxx.bean did you forget to inherit a required module? 没有源代码可用于类型xxxx.xxxx.bean您是否忘记继承所需的模块?

1) You can only include beans from the external jar library provided it is GWT compatible and declares a <ThirdPartyModuleName>.gwt.xml file which includes the package for the beans you need to use. 1)只有与GWT兼容的bean才能包含来自外部jar库的bean,并声明一个<ThirdPartyModuleName>.gwt.xml文件,其中包含您需要使用的bean的包。

2) You should have the <ThirdPartyModuleName> included in your own <Module>.gwt.xml using <inherits> tag. 2)您应该使用<inherits>标记将<ThirdPartyModuleName>包含在您自己的<Module>.gwt.xml

Given that your beans are in the package xxx.xxx.bean , and they are in an imported my_beans.jar library. 假设您的bean位于包xxx.xxx.bean ,并且它们位于导入的my_beans.jar库中。

Create a folder in your Application src tree (or src/main/java if you are using maven) with the name xxx/xxx 在Application src树中创建一个文件夹(如果使用maven,则为src/main/java ),名称为xxx/xxx

Create a new Module file in this folder called MyBeans.gwt.xml with this content: 在此文件夹中创建一个名为MyBeans.gwt.xml的新模块文件, MyBeans.gwt.xml包含以下内容:

<module>
  <inherits name='com.google.gwt.user.User'/>
  <source path="bean"/>
</module>

Edit your Application.gwt.xml and add this line 编辑Application.gwt.xml并添加此行

<inherits name="xxx.xxx.MyBeans"/>

Be aware that all Classes in the xxx.xxx.bean package must use classes supported by GWT. 请注意, xxx.xxx.bean包中的所有类都必须使用GWT支持的类。

You should check as well that the my_beans.jar library includes the java source files of the beans you are going to use. 您还应该检查my_beans.jar库是否包含您要使用的bean的java源文件。

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

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