GWT代码服务器在使用Maven原型生成的新项目中找不到模块

3
我已经使用GWT和Eclipse一段时间了,想尝试一下使用maven和GWT插件(gwt-maven-plugin, enter link description here)。我尝试在Eclipse之外的环境中使用它(Luna 4.4),但显然我没有正确地使用它,因为当我在pom.xml中更改一些小东西时,IDE会覆盖它的设置,导致它变得异常脆弱,经常出错。因此,我决定退一步,消除Eclipse的黑魔法,并从命令行开始一个新项目。

然而,我似乎无法运行实际应用程序,因为当我执行代码服务器并导航到页面时,我看到以下消息:

Can't find any GWT Modules on this page.

显然,代码服务器正在运行,但模块文件似乎没有被托管。据我所知,在自学几个小时后(并找到http://blog.ltgt.net/how-does-gwts-super-dev-mode-work/),应该有第二个进程实际上与代码服务器并行托管代码。使用maven做到这一点的适当方法是什么?我应该打开第二个终端并在代码服务器并行运行jetty或其他东西吗?如果是这样,能否有人请给我一个提示,如何最有效地完成它?
提前感谢!
以下是我创建项目的方式:
mvn archetype:generate \
   -DarchetypeGroupId=org.codehaus.mojo \
   -DarchetypeArtifactId=gwt-maven-plugin \
   -DarchetypeVersion=2.7.0
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype repository missing. Using the one from [org.codehaus.mojo:gwt-maven-plugin:2.7.0] found in catalog remote
Define value for property 'groupId': : com.mytest
Define value for property 'artifactId': : gwtmvntest
Define value for property 'version':  1.0-SNAPSHOT: :
Define value for property 'package':  com.mytest: : com.mytest.gwtmvntest
Define value for property 'module': : GwtMvnTest
Confirm properties configuration:
groupId: com.mytest
artifactId: gwtmvntest
version: 1.0-SNAPSHOT
package: com.mytest.gwtmvntest
module: GwtMvnTest
 Y: :
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: gwt-maven-plugin:2.7.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.mytest
[INFO] Parameter: artifactId, Value: gwtmvntest
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.mytest.gwtmvntest
[INFO] Parameter: packageInPathFormat, Value: com/mytest/gwtmvntest
[INFO] Parameter: package, Value: com.mytest.gwtmvntest
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: module, Value: GwtMvnTest
[INFO] Parameter: groupId, Value: com.mytest
[INFO] Parameter: artifactId, Value: gwtmvntest
[INFO] project created from Archetype in dir: /private/tmp/mvn/gwtmvntest
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 08:12 min
[INFO] Finished at: 2015-01-14T12:59:17+01:00
[INFO] Final Memory: 15M/310M
[INFO] ------------------------------------------------------------------------

这是我编译项目的步骤:

mvn compile gwt:compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building GWT Maven Archetype 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- gwt-maven-plugin:2.7.0:generateAsync (default) @ gwtmvntest ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ gwtmvntest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ gwtmvntest ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to /private/tmp/mvn/gwtmvntest/target/gwtmvntest-1.0-SNAPSHOT/WEB-INF/classes
[INFO]
[INFO] --- gwt-maven-plugin:2.7.0:compile (default-cli) @ gwtmvntest ---
[INFO] Compiling module com.mytest.gwtmvntest.GwtMvnTest
[INFO]    Compiling 5 permutations
[INFO]       Compiling permutation 0...
[INFO]       Process output
[INFO]          Compiling
[INFO]             Compiling permutation 4...
[INFO]       Process output
[INFO]          Compiling
[INFO]             Compiling permutation 3...
[INFO]       Process output
[INFO]          Compiling
[INFO]             Compiling permutation 2...
[INFO]       Process output
[INFO]          Compiling
[INFO]             Compiling permutation 1...
[INFO]    Compile of permutations succeeded
[INFO]    Compilation succeeded -- 13.866s
[INFO] Linking into /private/tmp/mvn/gwtmvntest/target/gwtmvntest-1.0-SNAPSHOT/GwtMvnTest
[INFO]    Link succeeded
[INFO]    Linking succeeded -- 0.171s
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.228 s
[INFO] Finished at: 2015-01-14T13:07:07+01:00
[INFO] Final Memory: 22M/310M
[INFO] ------------------------------------------------------------------------

这是我运行项目的方法:

mvn gwt:run-codeserver
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building GWT Maven Archetype 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> gwt-maven-plugin:2.7.0:run-codeserver (default-cli) > process-classes @ gwtmvntest >>>
[INFO]
[INFO] --- gwt-maven-plugin:2.7.0:generateAsync (default) @ gwtmvntest ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ gwtmvntest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ gwtmvntest ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< gwt-maven-plugin:2.7.0:run-codeserver (default-cli) < process-classes @ gwtmvntest <<<
[INFO]
[INFO] --- gwt-maven-plugin:2.7.0:run-codeserver (default-cli) @ gwtmvntest ---
[INFO] Turning off precompile in incremental mode.
[INFO] Super Dev Mode starting up
[INFO]    workDir: /var/folders/nk/58gyq85x7l3_mzb5rc0gw42w0000gn/T/gwt-codeserver-5859907708379954718.tmp
[INFO]    Loading Java files in com.mytest.gwtmvntest.GwtMvnTest.
[INFO]    Module setup completed in 11742 ms
[ERROR] 2015-01-14 13:14:35.800:INFO:oejs.Server:jetty-8.y.z-SNAPSHOT
[ERROR] 2015-01-14 13:14:35.833:INFO:oejs.AbstractConnector:Started SelectChannelConnector@127.0.0.1:9876
[INFO]
[INFO] The code server is ready at http://localhost:9876/

你仍然需要部署你的应用程序。GWT代码服务器允许您根据需要重新编译GWT代码(它替换所有JS代码,如果我没记错的话),但基本应用程序本身也需要运行。换句话说,按照通常的方式部署测试环境,然后启动代码服务器。 - Compass
感谢您的评论。有没有办法在Maven中做到这一点?我尝试在另一个窗口中运行“mvn tomcat7:run”。它会在http://localhost:8080/上提供HTML页面,但还是会显示“在此页面上找不到任何GWT模块”的消息。 - el.nicko
我检查了Tomcat提供的HTML。它引用了GwtMvnTest/GwtMvnTest.nocache.js,因此它试图在http://localhost:8080/下找到它,但实际上它并不存在那里。它实际上是由Code Server在http://localhost:9876/下提供的。有什么想法吗? - el.nicko
在运行Dev Mode On书签之前,http://localhost:8080/无法从http://localhost:9876/加载脚本。尽管如此,自GWT 2.7以来,事情变得更加容易;请参见下面的答案。 - Thomas Broyer
1个回答

7
使用GWT2.7+,您只需要启动mvn gwt:run,它将在后台使用SuperDevMode,并进行“重新编译加载”(而不是使用书签)。请注意,gwt:run不会复制您的src/main/webapp或依赖项,因此您可能需要先运行mvn war:exploded(或mvn package)(每次更改src/main/webapp中的文件或需要刷新依赖项时都要这样做)。
话虽如此,除非您的项目非常简单,否则您应该尽早为客户端和服务器端代码使用不同的Maven模块;这是因为Maven坚持认为您不能在同一个POM中管理“GWT客户端类路径”和“服务器端类路径”。我发布了原型来帮助设置所有内容:https://github.com/tbroyer/gwt-maven-archetypes(不幸的是,我还没有时间将它们更新到GWT 2.7)。或者使用Gradle...

谢谢Thomas。创建简单应用程序的原因是为了尽可能减少变量,以找到错误所在。我非常喜欢你的模块化Web应用程序原型,等我解决工具问题后一定会仔细研究它。我最初尝试了你的建议,使用mvn gwt:run,但是我无法看到建议的页面。 "GWT Development Mode"已经启动,但在浏览器中打开http://127.0.0.1:8888/GwtMvnTest.html页面时出现404 HTTP错误。请问您能否指点我正确的方向,为什么原型创建的"GwtMvnTest.html"没有被提供? - el.nicko
哈,你必须在使用mvn gwt:run之前运行mvn packagemvn war:exploded(或任何可以将你的src/main/webapp复制到target/gwtmvntest-1.0-SNAPSHOT并将你的依赖项复制到target/gwtmvntest-1.0-SNAPSHOT/WEB-INF/lib) 。 - Thomas Broyer
嗨,Thomas,我刚试了一下你的github页面上的模块化Web应用原型。按照你的建议简单创建了应用程序,然后执行了gwt:run。结果如下:目标org.codehaus.mojo:gwt-maven-plugin:2.7.0-rc1:run的参数'runTarget'缺失或无效。尝试在顶层pom.xml中更改为gwt 2.7.0,但没有成功。GWT 2.7.0也是如此。我喜欢这个项目分布得很好,但工具优先...我是否漏掉了一些明显的东西,为什么简单应用程序的HTML文件不能直接识别? - el.nicko
啊... 手掌->脸。谢谢! - el.nicko
1
非常感谢。在"gwt:run"之前执行"mvn package"解决了我的问题。 :) - Pasha

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