我刚刚开始使用 GWT。我使用Eclipse并安装了GWT插件。
我已按照此处的指示 Maven GWT 2.0 and Eclipse 进行操作使用 gwt-maven-plugin 设置 GWT 项目。当我运行 Maven 目标 gwt:compile gwt:run
时,会启动 GWT 开发模式,我可以将其中的 URL 复制到浏览器并查看标签。
但是项目存在这样的问题:
Description: The web.xml file does not exist
Resource: WEB-INF
Path: /GWTExample/war
Location: Unknown
Type: Google Web App Problem
如果我尝试将项目作为 Google Web 应用程序运行,我会收到以下警告:
[WARN] No startup URLs supplied and no plausible ones found -- use -startupUrl
我可以通过将 web.xml 复制到 war 目录来解决该问题,但在作为 Google Web 应用程序运行时,我仍然遇到 URL 问题。
如果我在 Eclipse 中使用 Maven 和 GWT,我是否应该忽略 web.xml 问题并始终通过 Maven 目标在开发模式下运行应用程序?或者有没有办法进行设置,以便我可以作为 Google Web 应用程序运行?
编辑:与上述相关,是否可以调试由 gwt:compile gwt:run
启动的在开发模式下运行的 GWT 应用程序?我已经在我的应用程序中添加了断点,但它并没有停止。我不确定这是我配置错误还是根本不可能。
更新:
回应Prem的回答...
当我运行 compile gwt:run
时,不会复制 web.xml 文件。当我运行 install gwt:run
时,出现以下错误:
[INFO] --- gwt-maven-plugin:1.2:test (default) @ SampleGWT ---
[INFO] using GWT jars from project dependencies : 2.0.4
[INFO] establishing classpath list (scope = test)
[ERROR] java.lang.NoClassDefFoundError: org/codehaus/mojo/gwt/test/MavenTestRunner
[ERROR] Caused by: java.lang.ClassNotFoundException: org.codehaus.mojo.gwt.test.MavenTestRunner
[ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[ERROR] at java.security.AccessController.doPrivileged(Native Method)
[ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
[ERROR] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[ERROR] Could not find the main class: org.codehaus.mojo.gwt.test.MavenTestRunner. Program will exit.
[ERROR] Exception in thread "main"
我猜这个错误 http://jira.codehaus.org/browse/MGWT-24包含在 gwt-maven-plugin 版本 1.2 中。通常我不会在构建 war 文件的项目上运行安装,但我希望至少能够通过构建周期的测试阶段。
有人知道为什么我会在安装时出现此错误,但在编译目标时却不会出现此错误吗?另外,我是否应该期望任一目标将 web.xml 文件从 src/main/webapp/WEB-INF/web.xml 复制到/war 目录?
最佳答案
Description: The web.xml file does not exist
gwt-maven-plugin 创建一个具有“war”打包格式的项目(它是一个 Web 应用程序,所以这里并不奇怪)。该项目的 Web.xml 将位于“src/main/webapp”文件夹下,该文件夹将被复制到“war”目录(设置为输出目录),作为 Maven 构建生命中“资源”阶段的一部分 -循环。您应该始终使用
mvn compile gwt:run
或
mvn install gwt:run
以便复制资源,编译所有 java 文件并调用 gwt:compile(因为它自动绑定(bind)到“编译”阶段)
[WARN] No startup URLs supplied and no plausible ones found -- use -startupUrl
根据您用作引用的 stackoverflow 链接,只有您的 Maven 构建文件是使用startupUrl 设置的。为了使其在 Eclipse 中工作,您必须编辑项目的运行配置,并将“-statupUrl”命令行参数添加到“参数”面板中的现有参数中。
但是,这只是一个警告,它不应该阻止您从 Eclipse 运行 GWT 应用程序。如果您在这里也遇到相同的“web.xml”问题,可能是因为您在调用“作为 Web 应用程序运行”之前没有在 IDE 中编译项目。我建议您禁用此项目的“自动构建”选项,并始终手动构建它并调用“GWT 编译”,然后尝试“作为 Web 应用程序运行”
EDIT: Related to the above, is it possible to debug a GWT app running in development mode started by gwt:compile gwt:run?
通常,您必须使用“远程应用程序”调试配置来远程调试进程。但是我不确定它是否适用于 GWT 项目。
关于eclipse - 使用 Eclipse/Maven 的 GWT 开发模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3568569/