GWT中的Super Dev模式

30

我是gwt的新手。我不知道如何启动Super Dev mode。我需要一步一步详细的解释。

我尝试通过添加编辑gwt.xml文件来解决问题,但是我无法启动Super Dev模式。

<add-linker name="xsiframe"/>
  <set-configuration-property name="devModeRedirectEnabled" value="true"/>
  <set-property name="compiler.useSourceMaps" value="true" />

但是我无法理解这个想法。

4个回答

63

更新:从GWT 2.7开始,DevMode将自动默认使用Super Dev Mode,因此您只需像以前一样启动DevMode,应用程序将在页面重新加载时自动编译。

一个区别是生成了一个特殊的.nocache.js文件,因此您必须确保浏览器加载了这个特定的文件;要调试远程服务器(就像之前在运行-noserver的DevMode中所做的那样),您必须按照下面描述的操作使用书签。

要在Super Dev Mode中运行,您必须经过两个准备步骤:

  1. Super Dev Mode only works with the xsiframe linker, so make sure you have the following line in your .gwt.xml too:

    <add-linker name="xsiframe" />
    

    That linker is safe for production use (Google uses it everywhere, slightly customized), so feel free to turn it on for all your projects (it combines the best of the std linker –the default one– and the xs linker, without their downsides).

    Note: that linker will be the default in 2.7

    If you use a version of GWT before 2.6.0, you'll also have to enable Super Dev Mode in your .gwt.xml:

    <set-configuration-property name="devModeRedirectEnabled" value="true" />
    

    Otherwise, if you intend to use Super Dev Mode from a URL different from 127.0.0.1 or localhost, then you'll have to whitelist the host. This is done using a regexp, e.g.:

    <set-configuration-property name="devModeUrlWhitelistRegexp" value="http://(mymachinename|192\.168\.5\.151)(:\d+)?/.*" />
    

    See https://dev59.com/QXzaa4cB1Zd3GeqPUcYU#21938574

  2. compile and deploy your app to a web server near you (if you used a .gwt.xml file specific to Super Dev Mode, make sure you compile that one module: the xsiframe linker and devModeRedirectEnabled property are necessary for that compilation step!)

    If you use GWT-RPC, set the system property gwt.codeserver.port to the port you'll run Super Dev Mode on (defaults to 9876) so your server can download RPC serialization policies right from the Super Dev Mode.
    If you run them on different machines, you'll have to override getCodeServerPolicyUrl in all of your RemoteServiceServlets. Consider the security implications though, as noted in the javadoc

完成上述步骤后,您可以开始启动超级开发模式会话:

  1. 使用和启动DevMode相同的classpath来启动com.google.gwt.dev.codeserver.CodeServer(例如:gwt-user.jargwt-dev.jar和所有客户端依赖项:如GXT, GIN+Guice, GWTEventBinder等),但同时添加gwt-codeserver.jar; 并将您的模块名称作为参数传递。

    它会开始编译您的模块以检查它是否可以实际编译; 您可以通过传递-noprecompile作为参数来跳过此步骤。

    如果您从未运行过Super Dev Mode,请转到http://localhost:9876并将Dev Mode OnDev Mode Off链接添加到书签中(将它们拖放到书签栏)。

    注意: 如果您使用Maven,您应该能够使用mvn gwt:run-codeserver(注意:插件发布版本2.6.0之前存在错误,您实际上必须运行mvn process-classes gwt:run-codeserver; 这在2.6.1中被修复)。

  2. 在浏览器中打开您的应用,然后点击Dev Mode On书签。在弹出的窗口中点击Compile按钮。它应该刷新页面并从CodeServer而不是从您的服务器加载JS。您的浏览器开发工具也应该加载SourceMaps以便您可以查看和调试(逐步)您的Java代码。

  3. 当您想测试您所做的更改时,再次点击Dev Mode On书签。与DevMode相反,刷新页面不会运行新代码; 必须先重新编译代码,这是在单击Dev Mode On书签后单击Compile按钮完成的(注意: 您也可以直接将Compile按钮添加到书签中以节省一个单击,但请注意它绑定到您的模块,因此如果您在多个模块上工作,则需要多个书签)。

  4. 完成后,点击Dev Mode Off,确保您切换回production mode,然后关闭CodeServer进程 (CtrlC在控制台中应该可以工作)。

官方文档请参考http://www.gwtproject.org/articles/superdevmode.html
另外,有关Super Dev Mode实际工作原理的更多信息,请参阅http://blog.ltgt.net/how-does-gwts-super-dev-mode-work/


在Eclipse或IntelliJ中会有调试支持吗?(我知道这可能像问一个神谕) - Christian Kuetbach
关于步骤#1中的警告,我该如何使用Maven保留两个*.gwt.xml文件并在Super Dev Mode和生产模式之间进行切换? - Thad
1
@Thad:这不是“The Maven Way™”,但你可以使用配置文件;请参见https://github.com/tbroyer/gwt-maven-archetypes/blob/598bed4f16a52d97b21a5f0fa9a3ce65650903a4/modular-webapp/src/test/resources/projects/basic-webapp/reference/basic-webapp-client/pom.xml以获取示例。或者,您可以简单地使用属性并从命令行覆盖其值。 - Thomas Broyer
@Thad 警告是无关紧要的。它在生产中是安全的,并且在 GWT 2.6.0-rc4 及之后版本中默认启用。 - Thomas Broyer
@ThomasBroyer 如果我按照所有步骤操作了,但是我遇到了浏览器获取错误,它找不到*.nocache.js文件(我没有更改任何内容,在主机模式下完全正常),此时该怎么办呢? - Adnane.T

16

遵循以下步骤,您一定会找到解决方案。

  1. 下载 GWT 2.5 RC2,并将其放在某个位置...我将其放在我的 eclipse/plugins 目录中。链接

  2. 在 Eclipse 中,将 GWT 2.5 添加到 Project -> Properties -> Google -> Web Toolkit -> Configure SDKs 屏幕中,并选择您在上一步中添加到目录中的 2.5 版本。

  3. 在 Eclipse 中右键单击项目,转到它的 Run Configurations 窗口,并创建一个新的 "Java 应用程序",给它取一个类似于 "GWT Super Dev Mode" 的名字。

  4. 在 Run Configurations 窗口中,执行以下操作:

    1. 根据您的项目名称设置项目,并将主类输入为 com.google.gwt.dev.codeserver.CodeServer

    2. Classpath 选项卡 上,点击 user Entries,然后点击 Add External JARs,导航至 GWT 2.5 目录,并找到 gwt-codeserver.jar,点击 "Open" (还有其他外部库)。

    3. 在 Arguments 选项卡中,将 -src src/ *您项目的源路径* 添加到 Program arguments,并添加可选的 -Xmx1024m 到 VM arguments。

    4. 单击 Apply,然后继续运行该项目。

  5. 之后,您将得到一个类似于 localhost:9876/ 的 URL。

  • 前往该网址,添加书签,分别为 开发模式开启开发模式关闭,然后运行代码,在网址中删除后缀 gwt.codesvr=127.00.1:9997。现在点击 开发模式开启...

  • 希望你能得到解决方案...


    为什么我收到“工作目录不存在”的错误信息? - EMM
    使用方法:至少需要提供一个模块。 - Ted Gulesserian
    1
    我解决了以下错误:“使用方法:必须提供至少一个模块”通过向CodeServer提供一个参数,该参数具有完全限定的包名。例如,com.somepackage.testgwt.TestGWT,其中TestGWT是对我的TestGWT.gwt.xml文件的引用。 - Ted Gulesserian

    7

    当代码停在断点上时,我只能观察JavaScript。是否可以调试Java代码(在其转换为JavaScript之前添加对Java变量的监视)? - kirilv

    4

    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接