【问题标题】:Maven and GWT (and Eclipse) - Does it really work?Maven 和 GWT(和 Eclipse)——它真的有效吗?
【发布时间】:2011-04-06 13:00:03
【问题描述】:

在过去的几天里,我一直在尝试使用 gwt-maven-plugin 在 Eclipse 中创建/运行一个项目,但一直遇到障碍(请参阅我之前的一些问题)。我喜欢使用 Maven 进行构建,但由于使用 Maven 的复杂性,我正考虑采用 Ant 构建路线。

那里有人配置/运行良好吗?是我自己还是这比应该的更难?

【问题讨论】:

  • 这篇最近在 GWT 博客上的帖子可能会有所帮助...googlewebtoolkit.blogspot.com/2010/08/…
  • @Jason Hall,感谢您的链接。我使用 gwt-maven-plugin 原型创建了一个新项目,然后按照博客上的步骤将现有 Maven 项目转换为使用 GWT。我能够运行该应用程序,但在尝试调试它时遇到了与我在下面对 helios 的评论中相同的错误。 :(

标签: java eclipse gwt maven


【解决方案1】:

对于 Eclipse,我使用:m2eclipse 插件 (1.0)。它适用于一两件小事。还可以下载 m2eclipse-extras 插件以添加 SVN 功能和 Maven(或 CVS,如果您愿意)。

当您下载项目时,它会读取 pom.xml 并 [重新] 创建 Eclipse 配置文件,如 mvn eclipse:eclipse 命令。

对于 GWT……我也用过。这是一个非常复杂的配置,但它可以工作。我使用 GWT 2.0.3,maven-gwt-plugin 使用依赖项来工作(没有对 GWT SDK 的引用),它可以从 Eclipse 进行调试,这简直太棒了。

你必须编译到一个战争目录(不是目标/类标准)。但是细节在我的工作中,所以让我明天看看并完成这个答案:) 不要放弃。拥有 GWT+Eclipse+Maven 真是太好了。

编辑:我的配置的一部分

<build>...
<outputDirectory>war/WEB-INF/classes</outputDirectory>
...
</build>


        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>1.2</version>
            <configuration>
                <gwtVersion>${gwt.version}</gwtVersion> <!-- para forzar que use el de maven y no el SDK instalado -->
                <disableCastChecking>true</disableCastChecking>
                <disableClassMetadata>true</disableClassMetadata>
                <runTarget>/subscriber/listSubscribers.htm</runTarget>
                <webappDirectory>${basedir}/war</webappDirectory>
                <soyc>true</soyc>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>


                    <!-- dont know/remember if the jetty inside the gwt uses this... but it doesnt hurt-->
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <version>6.1.14</version>
            <configuration>
                        <webAppConfig>
                        <contextPath>/magazine</contextPath>
                        <baseResource implementation="org.mortbay.resource.ResourceCollection">
                        <resourcesAsCSV>
                                ${basedir}/src/main/webapp,
                                ${basedir}/war
                            </resourcesAsCSV>
                        </baseResource>
                </webAppConfig>
                <connectors>
                    <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                        <port>8888</port>
                        <maxIdleTime>60000</maxIdleTime>
                    </connector>
                </connectors>
                <scanIntervalSeconds>3</scanIntervalSeconds>
                <scanTargets>
                    <scanTarget>${basedir}/war</scanTarget>
                </scanTargets>                  
            </configuration>
        </plugin>

为了调试,我创建了两个任务:

1) 运行两个目标的 Eclipse 内的 maven 构建:war:exploded gwt:debug

  • 第一个将所有资源复制到war目录中,供gwt调试使用。
  • 接下来 gwt 准备就绪。

也许你需要第一次执行gwt:compile

2) Java 远程应用程序调试配置,选择您的项目。

当 gwt:debug 是“监听 8000 端口”时运行此配置

AND:这是在父 pom.xml 中(抱歉,我稍后会编辑这篇文章 :)

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1-alpha-2</version>
            <configuration>
                <warSourceDirectory>${basedir}/src/main/webapp</warSourceDirectory>
                <webappDirectory>${basedir}/war</webappDirectory>
                <warName>${artifactId}</warName>
            </configuration>
        </plugin>

【讨论】:

  • 我应该提到我也使用 m2eclipse 插件。我不相信我有额外的东西,但我们使用 Mercurial 作为我们的版本控制系统。我已将 maven-war-plugin warSourceDirectory 设置为“war”目录。我认为我正在做我应该做的事情,但总是遇到问题。目前我无法运行 gwt:debug 因为我收到错误 [ERROR] Failed to execute goal org.codehaus.mojo:gwt-maven-plugin:1.2:debug (default-cli) on project MyProject: Command [ [ ......]] 失败,状态为 1,我不知道为什么...
  • 嗨,最近几天我花了一些时间试图让 GWT/Maven 在基于此博客 (googlewebtoolkit.blogspot.com/2010/08/…) 的 Eclipse 中工作,但无济于事。当您说“no ref to GWT SDK”时,您的意思是您没有安装 GWT Eclipse 插件吗?
  • 不。我的意思是 gwt-maven-plugin 使用 gwt-user 和 gwt-servlet 依赖项(嗯……我没有在示例中包含它)来编译项目的 GWT 部分。
  • 就是:gwt-maven-plugin可以使用gwt sdk主目录或者你的依赖。它适用于我的依赖项,因此不需要对任何 GWT SDK 本地路径的引用。
【解决方案2】:

它应该更难,但它是可能的。此处发布的所有提示都可以解决问题。但是,您仍然可能遇到类加载问题。我决定切换到 GWT 2.1 并使用 JettyLauncher 的新功能。您可以像这样创建自己的码头启动器:

public class MyJettyLauncher extends com.google.gwt.dev.shell.jetty.JettyLauncher {
  @Override
  protected WebAppContext createWebAppContext(TreeLogger logger, File appRootDir) {
    return new WebAppContext(appRootDir.getAbsolutePath(), "/");
  }
}

然后将-server MyJettyLauncher 选项添加到您的gwt 启动器配置中。有了这样的配置,所有的库都由 m2eclipse 管理(你甚至可以从类路径中删除 GWT SDK)并且不需要复制任何东西到WEB-INF/lib(你可以删除可能已经存在的gwt-servlet.jar)。

就绪启动器位于 tadedon 库中: http://code.google.com/p/tadedon/source/browse/tadedon-gwt-dev/src/main/java/com/xemantic/tadedon/gwt/dev/JettyLauncher.java

【讨论】:

    【解决方案3】:

    在试图让事物很好地融合在一起感到非常沮丧之后,这就是我拥有的对我“有效”的设置。 “Works”意味着我可以通过调整创建、运行和调试 GWT 项目,但这不是最优雅的解决方案。

    创建项目

    大部分步骤与 Pascal 在这篇文章中的回答相同:Maven GWT 2.0 and Eclipse。为了清楚起见,我会列出我的。

    在安装了 m2eclipse 和 GWT Eclipse 插件的 Eclipse (Helios) 中:

    使用 gwt-maven-plugin 原型创建一个新的 Maven 项目

    修改pom.xml:

    • &lt;gwt.version property&gt; 设置为2.0.4 (需要和 GWT Eclipse 一样 插件版本)
    • 设置&lt;maven.compiler.source&gt;&lt;maven.compiler.target&gt; 属性 1.6
    • 删除&lt;goal&gt;generateAsync&lt;/goal&gt; 来自 gwt-maven-plugin &lt;plugin&gt; 配置
    • 在 pom.xml 中添加 maven-war-plugin

    maven-war-plugin 示例:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
        <warSourceDirectory>war</warSourceDirectory>
            <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
        </configuration>
    </plugin>
    

    更新项目属性:

    • Google -> Web Toolkit,选中“Use Google Web Toolkit”框,并确保选中“Use default SDK (GWT-2.0.4)”。

    在项目上运行 Maven "gwt:eclipse" 目标(设置环境并启动配置)

    复制 *.launch 文件到 workspace.metadata.plugins\org.eclipse.debug.core.launches

    重启 Eclipse

    编译/运行项目

    我创建了一个执行mvn clean compile gwt:run 的运行配置。 gwt:run 是将资源和 lib jar 复制到 war 目录所必需的。但是,它不会将 web.xml 从 src/main/webapp/WEB-INF 复制到 war/WEB-INF/。所以,我必须手动复制该文件。

    如果我想运行我的应用程序,上述步骤就足够了。但是,如果我想调试应用程序,我会通过从先前复制 .launch 文件时创建的调试配置中选择 Google“Web 应用程序”配置来启动它。此配置允许调试(断点等),无需任何其他配置或远程调试。

    【讨论】:

    • 小心升级到 Eclipse Indigo 和 M2 1.0。让它再次工作,我遇到了无穷无尽的麻烦。
    【解决方案4】:

    helios 写了很好的解释。但目前还不是真的。所以我建议你试试我的现代example of EAR application running on GlassFish and with full debug support

    【讨论】:

      【解决方案5】:

      是的,2016 年确实如此,确实非常好。 :)

      我从 Eclipse 中启动 Tomcat,我从 Eclipse 启动 GWT 代码服务器(SuperDev 模式),我从 Eclipse 启动 Chrome。

      您可以在 Brandon Donnelson 的 YouTube 频道上找到最新且非常有价值的设置教程:https://www.youtube.com/user/branflake2267/videos

      对我来说最重要的是 GWT SuperDevMode 的 Eclipse 调试器https://sdbg.github.io/

      我更喜欢“mavenized”我的项目,并且有很多 Brandon 也提供了 Maven 原型https://github.com/branflake2267/Archetypes/tree/master/archetypes

      下载 GPE 插件(不要与上面提到的调试器插件混淆)的官方起点(不仅仅是)在 GwtProject.comhttp://www.gwtproject.org/download.html
      对我个人而言,GPE 本身已成为相当可选的“便利”组件。 (是的,重构和自动完成功能很不错,但仅此而已。:)

      这不是一键式解决方案,我更喜欢这样,因为它们往往是容易破坏的黑盒。

      顺便说一句,请务必查看 GWT 材料http://gwtmaterialdesign.github.io/gwt-material-demo/

      (目前正在使用 2.8-beta1。)

      【讨论】:

        猜你喜欢
        • 2011-01-20
        • 2011-05-09
        • 2012-06-03
        • 2017-12-17
        • 1970-01-01
        • 1970-01-01
        • 2019-02-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多