使用 Eclipse/Maven 的 GWT 开发模式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3568569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:02:52  来源:igfitidea点击:

GWT Development Mode with Eclipse/Maven

eclipsegwtmaven-2

提问by sdoca

I am just starting with GWT. I use Eclipse and have installed the GWT plugin.

我刚开始使用 GWT。我使用 Eclipse 并安装了 GWT 插件。

I have followed the directions here Maven GWT 2.0 and Eclipseto set up a GWT project using the gwt-maven-plugin. When I run the Maven goals gwt:compile gwt:run, GWT Development Mode is launched and I can copy the url from it to my browser and view the label.

我已经按照Maven GWT 2.0 和 Eclipse 的说明使用 gwt-maven-plugin 设置了 GWT 项目。当我运行 Maven 目标时gwt:compile gwt:run,会启动 GWT 开发模式,我可以将 url 从中复制到我的浏览器并查看标签。

However, the project has this problem:

但是,该项目有这个问题:

Description: The web.xml file does not exist
Resource: WEB-INF   
Path: /GWTExample/war
Location: Unknown
Type: Google Web App Problem

If I try to run the project as a Google Web Application, I get this warning:

如果我尝试将项目作为 Google Web 应用程序运行,则会收到以下警告:

[WARN] No startup URLs supplied and no plausible ones found -- use -startupUrl

I can get rid of the problem by copying the web.xml to the war directory, but I still get the URL issue when running as a Google Web App.

我可以通过将 web.xml 复制到 war 目录来解决这个问题,但是当作为 Google Web App 运行时,我仍然遇到 URL 问题。

If I'm using Maven and GWT in Eclipse, should I just ignore the web.xml problem and always run applications in development mode via the Maven goals? Or is there a way to set things so I can run as a Google Web App?

如果我在 Eclipse 中使用 Maven 和 GWT,我是否应该忽略 web.xml 问题并始终通过 Maven 目标在开发模式下运行应用程序?或者有没有办法设置一些东西,以便我可以作为 Google Web App 运行?

EDIT: Related to the above, is it possible to debug a GWT app running in development mode started by gwt:compile gwt:run? I have added breakpoints to my application but it doesn't stop on them. I'm not sure if it is something I've configured wrong or if it's just not possible.

编辑:与上述相关,是否可以调试在开发模式下运行的 GWT 应用程序gwt:compile gwt:run?我已经在我的应用程序中添加了断点,但它并没有停止。我不确定这是我配置错误还是根本不可能。

Update:

更新:

In response to Prem's answer...

为了回应Prem的回答......

When I run a compile gwt:run, the web.xml file isn't copied. When I run the install gwt:run, I get this error:

当我运行 a 时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.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"

I'm guessing that bug http://jira.codehaus.org/browse/MGWT-24is included in version 1.2 of the gwt-maven-plugin. Normally I wouldn't run install on a project that builds a war file, but I would expect to at least get past the test phase of the build cycle.

我猜这个错误http://jira.codehaus.org/browse/MGWT-24包含在 gwt-maven-plugin 的 1.2 版中。通常我不会在构建War文件的项目上运行安装,但我希望至少能通过构建周期的测试阶段。

Does anybody have any idea why I would get this error on the install but not the compile goals? Also, should I be expecting either goal to copy the web.xml file from src/main/webapp/WEB-INF/web.xml to the /war directory?

有没有人知道为什么我会在安装时出现这个错误而不是编译目标?另外,我是否应该期望将 web.xml 文件从 src/main/webapp/WEB-INF/web.xml 复制到 /war 目录?

回答by Prem

Description: The web.xml file does not exist

描述:web.xml 文件不存在

gwt-maven-plugin creates a project with 'war' packaging format (it's a web app so no surpirse here). Web.xml for this project will be under 'src/main/webapp' folder which will be copied to the 'war' directory (which is set as the output directory) as part of the 'resources' phase in the maven build life-cycle. You should always use

gwt-maven-plugin 创建了一个带有“war”打包格式的项目(它是一个网络应用程序,所以这里没有惊喜)。这个项目的 web.xml 将在 'src/main/webapp' 文件夹下,该文件夹将被复制到 'war' 目录(设置为输出目录)作为 Maven 构建生命中的 'resources' 阶段的一部分 -循环。你应该总是使用

mvn compile gwt:run

mvn 编译 gwt:运行

or

或者

mvn install gwt:run

mvn 安装 gwt:运行

so that resources are copied, all java files are compiled and gwt:compile is also invoked (since it is bound to the 'compile' phase automatically)

以便复制资源,编译所有 java 文件并调用 gwt:compile (因为它自动绑定到 'compile' 阶段)

[WARN] No startup URLs supplied and no plausible ones found -- use -startupUrl

[警告] 未提供启动 URL,也未找到合理的 URL -- 使用 -startupUrl

As per the stackoverflow link you used as reference, only your maven build file is setup with startupUrl. In order for it to work in Eclipse, you must edit the Run Configuration of your project and add the '-statupUrl' command line arguments to the existing arguments in the "Arguments" panel.

根据您用作参考的 stackoverflow 链接,只有您的 Maven 构建文件是使用 startupUrl 设置的。为了让它在 Eclipse 中工作,您必须编辑项目的运行配置并将“-statupUrl”命令行参数添加到“参数”面板中的现有参数。

However, this is just a warning and it should not stop you from running your GWT application from eclipse. If you are facing the same "web.xml" problem here as well, it could be because you did not compile your project in your IDE before invoking "Run as Web Application". I suggest you to disable "Build Automatically" option for this project and always build it manually and invoke "GWT Compile" and then try "Run as web application"

但是,这只是一个警告,不应阻止您从 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:compile gwt:run 启动的开发模式下运行的 GWT 应用程序?

In general you must use "Remote Application" debug configuration for remote debugging a process. However I am not sure if it will work for GWT projects.

通常,您必须使用“远程应用程序”调试配置来远程调试进程。但是我不确定它是否适用于 GWT 项目。

回答by Prem

I got me too this warning:

我也收到了这个警告:

No startup URLs supplied and no plausible ones found

未提供启动 URL,也未找到合理的 URL

when I have followed this gwt tutorial

当我遵循 这个 gwt 教程时

In that screenshot there is no checkbox with "Generate sample code" . In my IDE ( sdk 2.5) it is, so I have unchecked...

在该屏幕截图中,没有带有“生成示例代码”的复选框。在我的 IDE ( sdk 2.5 ) 中是这样,所以我没有选中...

It wasn't created any of the serverand clientpackages, I have created the clientmanually, as the tutorial required. The tutorial until that step doesn't say I must have a serverpackage too. That and his configuration is missing from project.

它没有创建任何serverclient包,我已经client按照教程要求手动创建了。直到那一步的教程并没有说我也必须有一个server包。项目中缺少那个和他的配置。

回答by user9901

If you right-click on your project and go to Properties -> Google -> Web Application, your WAR directory might be something like either waror src/main/webapp/WEB-INF/classes.

如果您右键单击您的项目并转到 Properties -> Google -> Web Application,您的 WAR 目录可能类似于warsrc/main/webapp/WEB-INF/classes.

Change that to src/main/webapp. Also un-check the box next to "Launch and delploy from this directory..."

将其更改为src/main/webapp. 同时取消选中“从此目录启动和部署...”旁边的框

That's what fixed this problem for me. It also fixed the "can't find gwt-servlet.jar" problem at the same time.

这就是为我解决这个问题的原因。同时也修复了“找不到gwt-servlet.jar”的问题。