简体   繁体   English

如何在生产模式下运行GWT

[英]How to run GWT in production mode

I am trying to run GWT project in production mode, as per the instructions at https://developers.google.com/web-toolkit/usingeclipse . 我按照https://developers.google.com/web-toolkit/usingeclipse上的说明尝试在生产模式下运行GWT项目。 So my project foo is located as a folder foo in my desktop under th workspace folder. 所以我的项目foo位于workspace文件夹下的桌面文件夹foo中。 When I right click on the foo project in the Project Explorer, click Google - GWT Compile , I see some message like permutations 1, 2.. etc in the debugging console, after which it says that compilation is complete. 当我在Project Explorer中右键单击foo项目时,单击Google - GWT Compile ,我在调试控制台中看到一些消息,如permutations 1, 2..等等,之后它表示编译完成。

However, contrary to what the Google page says, no additional HTML / Javascript files are generated in the war folder. 但是,与Google页面所说的相反, war文件夹中不会生成其他HTML / Javascript文件。 Also, if I enter foo/war/foo.html in the URL bar, I am getting a timed-out error (even though the page contains only a simple alert call). 另外,如果我在URL栏中输入foo/war/foo.html ,我会收到一个超时错误(即使该页面只包含一个简单的alert调用)。

Can anyone tell me what is going on here? 谁能告诉我这里发生了什么?

If you are running in GWT development mode after the compile 如果在编译后运行在GWT开发模式下

remove the parameter gwt.codesvr=127.0.0.1:9997 in the url given by eclipse 在eclipse给出的url中删除参数gwt.codesvr=127.0.0.1:9997

After you compile the code the whole gwt code will convert in to javascript so you can access like an normal HTML page with proper paths . 在编译代码之后,整个gwt代码将转换为javascript因此您可以像使用正确路径的普通HTML页面一样进行访问。

如果您的GWT项目是Maven项目,并且您正在使用gwt-maven-plugin ,则可以运行mvn jetty:run-war (例如,使用它作为Eclipse Maven运行配置的目标):这将GWT编译您的投射到战争中,并在localhost上运行它,从而运行你的Prod模式。

This can test ui-only features in Production Mode. 这可以在生产模式下测试仅限ui的功能。 That's useful if that's all you need to do, especially if otherwise the running of a server for Production Mode occupies limited resources of your development machine that you'd like to save (whereas occupying them with a running server would be a "waste" if your testing doesn't need to make requests to that server anyways). 如果您只需要这样做,那将非常有用,特别是如果生产模式的服务器的运行占用了您想要保存的开发机器的有限资源(而使用正在运行的服务器占用它们将是“浪费”,如果无论如何,您的测试不需要向该服务器发出请求。

If your GWT project... 如果你的GWT项目......

  1. doesn't make any server requests for data yet (maybe your project is still in its infancy as well), and... 还没有任何服务器请求数据(也许你的项目仍然处于初期阶段),并且......
  2. is a Maven project 是一个Maven项目

... you can... ... 您可以...

  1. GWT compile your project GWT编译你的项目
  2. Maven package (those directions use gwt-Eclipse-maven-plugin ) your project Maven包 (那些指示使用gwt-Eclipse-maven-plugin )你的项目
  3. open the packaged GWT host page (ie: index.html, or < Your Module >.html, under yourProject/target/yourProject-< snapshot version >/) in a browser. 在浏览器中打开打包的GWT主页(即:index.html,或<Your Module> .html,在您的Project / target / yourProject- <snapshot version> /下)。 Profit! 利润!

This is sufficient to test the project's ui-only features, thus in Production Mode. 这足以测试项目的ui-only功能,因此在生产模式下。 In fact, if your project has features that make server requests for data, but you aren't testing any of them, then this will still work to test just those ui-only features. 实际上,如果您的项目具有使服务器请求数据的功能,但您没有测试任何数据,那么这仍然只能测试那些仅限ui的功能。 Basically, any features requesting server data will not have those requests returned (as there is no server running to do that), but all other features will function, as they are ui-only. 基本上,任何请求服务器数据的功能都不会返回那些请求(因为没有服务器运行来执行此操作),但所有其他功能都将起作用,因为它们只是ui-only。

If you need to test features that make server requests for data, then you'll have to run Production Mode via a server (that would respond to the requests). 如果您需要测试使服务器请求数据的功能,那么您必须通过服务器运行生产模式(这将响应请求)。 For example with Jetty server, see my other Answer here. 例如,使用Jetty服务器,请参阅我的其他答案

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

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