简体   繁体   English

在GWT中以托管模式运行小部件

[英]Running widgets in hosted mode in GWT

I am building complicated widgets for Google Web Toolkit. 我正在为Google Web Toolkit构建复杂的小部件。 These widgets are compiled to a jarfile, which I include in other projects. 这些小部件被编译为jarfile,我将其包含在其他项目中。 At the moment I have to compile the jar and startup the other project in hosted mode to test my widget. 目前,我必须编译jar并以托管模式启动另一个项目以测试我的小部件。 This is rather slow. 这相当慢。 Does somebody if it's possible to test widgets in hosted mode directly? 是否有人可以直接在托管模式下测试小部件?

My structure is as follows: 我的结构如下:

  • com.example.gwt with a xxx.gwt.xml file com.example.gwt和xxx.gwt.xml文件
  • com.example.components.emailform with the composite and a uibinder xml file com.example.components.emailform与组合和uibinder xml文件

What else do I need to run the hosted mode? 我还需要什么来运行托管模式? I do not need any client/server interaction, and I would like to keep any additional files to a minimum, in order to not mess up my jar. 我不需要任何客户端/服务器交互,并且我希望将所有其他文件保持在最低限度,以免弄乱我的jar。

The easiest thing is to add an entrypoint definition to your module xxx.gwt.xml file. 最简单的方法是将入口点定义添加到模块xxx.gwt.xml文件中。
In the entrypoint class you can instantiate your widget and add it to a RootLayoutpanel or RootPanel . 在入口点类中,您可以实例化窗口小部件并将其添加到RootLayoutpanelRootPanel

Module xml file: <entry-point class="com.xxx.xxx.MyWidgetTest" /> 模块xml文件: <entry-point class="com.xxx.xxx.MyWidgetTest" />

MyWidgetTest.class: MyWidgetTest.class:

public class MyWidgetTest implements EntryPoint {

    @Override
    public void onModuleLoad() {
         MyWidget myWidget = new MyWidget();
         RootLayoutPanel.add(myWidget);
    }
}

Even if you don't use a web-server you probably have to add a host page (html page) where you load your nocache.js bootstrap file. 即使您不使用网络服务器,也可能必须添加一个宿主页面(html页面),以便在其中加载nocache.js引导程序文件。

<script type="text/javascript" language="javascript" src="xxx.nocache.js" />

You can create a second xxx.gwt.xml file that doesn't contain the entrypoint definition. 您可以创建不包含入口点定义的第二个xxx.gwt.xml文件。 This second xxx.gwt.xml module file can be packaged with your jar file (using Ant or maven) and you can exclude the MyWidgetTest class file from your jar package. 第二个xxx.gwt.xml模块文件可以与jar文件一起打包(使用Ant或maven),并且可以从jar包中排除MyWidgetTest类文件。

Please have a look at GWT documentation regarding modules and libraries . 请查看有关模块库的 GWT文档。 I guess that is what you are looking for. 我想这就是您要寻找的。

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

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