【问题标题】:How do I get GWT Super Dev Mode / SuperDevMode to include my html file?如何让 GWT Super Dev Mode / SuperDevMode 包含我的 html 文件?
【发布时间】:2013-12-30 16:49:28
【问题描述】:

我关注this answer(感谢 Ed)发现他并没有完全解决问题。

我已经启动并运行了 SuperDevMode / CodeServer,但它不包含我的 html 文件,这使它有点没用。我真的需要运行 2 个 Web 服务器吗?

我正在使用 Gradle,如果这很重要的话。

【问题讨论】:

    标签: java gwt gradle gwt-super-dev-mode


    【解决方案1】:

    如果您没有任何服务器端,那么您可以简单地将您的 HTML 主机页面放在您的 public path 中,而不是放在 war 文件夹中,然后它将由SuperDevMode CodeServer,因为它现在是模块的一部分。不要忘记调整您的<script>*.nocache.js 将是页面的兄弟。

    【讨论】:

    • 很棒的建议。我没有想到这一点。事实上,我也可以将其余的服务器端内容(图像、html)放在该公共路径中,然后代码服务器会工作得更好。在玩了大约 4 个小时之后,我实际上放弃了这个项目。我认为超级开发模式还为时过早。编译我的模块需要 23 秒,每次代码更改后我都需要等待。这距离我目前的 5 到 10 秒已经足够远了,可以等待开发模式使其成为交易杀手。
    • 通过任何服务器端,我说的是代码:图像不是服务器端。至于 SuperDevMode 的性能,确实有改进的空间:生成器必须支持增量运行(缓存结果而不是每次都重新生成),目前只有 RPC 和 ClientBundle 可以:不是 UiBinder,不是 Editor,不是 RequestFactory,等等。其中会减慢编译速度。期待在以后的版本中有更好的表现。 SuperDevMode 被标记为 experimental 是有原因的 ;-)
    【解决方案2】:

    这是我想出的答案。在我的 HTML 文件中,我删除了加载 *.nocache.js 的脚本,而是动态生成它,如下所示:

    <script type="text/javascript">
        function loadScript(scriptSrc)
        {
            var scriptTag = document.createElement('script');
            scriptTag.type = 'text/javascript';
            scriptTag.async = true;
            scriptTag.src = scriptSrc;
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(scriptTag, s);
        }
    
        // Load the GWT script
        loadScript(('file:' == document.location.protocol ? "http://localhost:9876/" : "") + "admin/admin.nocache.js");
    </script>
    

    我的运行代码服务器的 Gradle 任务如下所示:

    task codeServer(dependsOn: "war") << {
        println("*----------------------------------------------------------------------------------------------*")
        println("   Ignore what this says below about going to http://localhost:9876/")
        println("   Instead, once the server below is up, in a separate command line, type:")
        println("       start $buildDir\\exploded\\Admin.html")
        println("*----------------------------------------------------------------------------------------------*")
    
        def gwtTempDir = "$buildDir/gwtTemp"
        (new File(gwtTempDir)).mkdirs()
    
        ant.java(classname: "com.google.gwt.dev.codeserver.CodeServer", failonerror: "true", fork: "true") {
            classpath {
                pathElement(location: "src/main/java")
                pathElement(location: "src/main/resources")
                pathElement(location: "$buildDir/classes/main")
                pathElement(path: configurations.compile.asPath)
            }
            jvmarg(value: "-Xmx512m")
            sysproperty(key: "java.util.logging.SimpleFormatter.format", value: System.getProperty("java.util.logging.SimpleFormatter.format"));
            arg(line: "-workDir " + gwtTempDir)
            arg(line: "-src " + "src/main/java")
            arg(value: "com.onlyinsight.oventio.Admin")
        }
    }
    

    所以现在,我可以将浏览器指向 file:///F:/projects/ConferenceModule/build/exploded/Admin.html,而不是第二个网络服务器,这一切都可以正常工作。

    我希望这对其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-23
      相关资源
      最近更新 更多