【问题标题】:Create a GWT Maven Project创建 GWT Maven 项目
【发布时间】:2011-09-26 07:10:09
【问题描述】:

我正在尝试使用 Eclipse 创建一个新项目,以便在 maven 2 系统下创建 GWT 应用程序。 我已经使用以下 mvn 命令创建了项目

mvn archetype:generate -DarchetypeRepository=repo1.maven.org -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.3.0

我已经安装了以下 Eclipse 插件: * m2eclipse * 鸡蛋 * gwt 插件

这是我的 POM 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <!-- POM file generated with GWT webAppCreator -->
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mobc3.paperquid</groupId>
  <artifactId>Backoffice</artifactId>
  <packaging>war</packaging>
  <version>1.0.0-SNAPSHOT</version>
  <name>GWT Maven Archetype</name>

  <properties>
    <!-- Convenience property to set the GWT version -->
    <gwtVersion>2.3.0</gwtVersion>
    <!-- GWT needs at least java 1.5 -->
    <maven.compiler.source>1.5</maven.compiler.source>
    <maven.compiler.target>1.5</maven.compiler.target>
    <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <version>2.3.0</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <version>2.3.0</version>
      <scope>provided</scope>
    </dependency>  
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.7</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <!-- Generate compiled stuff in the folder used for developing mode -->
    <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>

<plugins>

      <!-- GWT Maven Plugin -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>2.3.0</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>test</goal>
              <goal>i18n</goal>
              <goal>generateAsync</goal>
            </goals>
          </execution>
        </executions>
        <!-- Plugin configuration. There are many available options, see gwt-maven-plugin 
          documentation at codehaus.org -->
        <configuration>
          <runTarget>Backoffice.html</runTarget>
          <hostedWebapp>${webappDirectory}</hostedWebapp>
          <i18nMessagesBundle>com.mobc3.paperquid.backoffice.client.Messages</i18nMessagesBundle>
        </configuration>
      </plugin>

      <!-- Copy static web files before executing gwt:run -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>exploded</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <webappDirectory>${webappDirectory}</webappDirectory>
        </configuration>
      </plugin>

    </plugins>
  </build>

</project>

我可以使用 linux shell 编译和部署我的应用程序,但是我在 eclipse 中构建和运行应用程序时遇到了很多问题。

我还没有找到任何教程来解释如何在 Eclipse 中的 maven 下逐步创建 GWT 应用程序。

有人可以帮我吗?

【问题讨论】:

    标签: eclipse gwt maven-2 maven maven-plugin


    【解决方案1】:

    另一种选择:

    • 在 Eclipse 中使用 gwt 插件创建一个 gwt 项目。现在您有了一个 Eclipse gwt 项目。
    • 选择Project Explorer中的项目,右键单击,然后选择Configure。然后选择Convert to Maven Project。现在你得到了一个 gwt-maven 项目。
    • 现在将必要的依赖项添加到pom.xml

    【讨论】:

    • 按照您的建议,我可以使用 Run As -> (Google)Web Application 在 Eclipse 中运行我的项目。但是,当我尝试运行方式-> 在服务器上运行时,我得到“禁止”。有人可以帮我理解并修复这个错误吗?
    【解决方案2】:

    当我使用 gwt:run 目标运行我的 GWT 应用程序时,这是我的 pom 设置中的相关(我认为)部分:

    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>gwt-maven-plugin</artifactId>
      <version>2.3.0</version>
      <configuration>
        <runTarget>/ModuleName.html</runTarget>
        <modules>
          <module>${project.groupId}.package.ModuleName</module>
        </modules>
        <copyWebapp>true</copyWebapp>
      </configuration>
      <executions>
        <execution>
          <configuration>
            <extraParam>true</extraParam>
          </configuration>
          <goals>
            <goal>compile</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    

    不过,我应该说,我现在使用 GWT Eclipse 插件在 Eclipse 中运行我的应用程序,所以我已经有一段时间没有使用这个配置了。从我记得阅读的内容来看,“copyWebapp”“true”是配置的关键部分之一。它还帮助我直接指定模块名称,因为 gwt-maven-plugin 有时无法找到它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-04
      • 2011-07-12
      • 2013-02-15
      • 1970-01-01
      • 1970-01-01
      • 2012-02-02
      • 2012-06-03
      • 2017-06-16
      相关资源
      最近更新 更多