Maven GWT 2.0 和 Eclipse

2022-08-31 20:19:35

有谁知道使用maven和eclipse使用新的2.0版本的GWT创建项目的好指南?我遇到了很多问题,让他们一起玩得很好。

就其价值而言,我可以使用maven eclipse插件创建一个gwt项目,该项目工作正常,但是将其移植到maven不起作用(因此本指南会很棒)。

同样,我可以使用 maven 插件(gwt-maven-plugin),但是当我导入它来 eclipse(import ->实现 maven 项目)时,它不会被识别为 GWT 项目...

谢谢


答案 1

编辑:我已使用 OP 提供的其他步骤更新了我的答案。详细信息请注明 OP。

我刚刚破坏了我的Eclipse设置,试图安装最新版本的Google Plugin for Eclipse(用于GWT 2.0),所以我无法确认所有内容,但是,让我们假设满足以下先决条件:

您是否尝试过:

  1. 从 Eclipse 创建一个新项目(“新建>其他...”,然后选择“Maven 项目”并选择 gwt-maven-plugin 原型)。

  2. 编辑生成的 ,将属性更新为(已在中央存储库中发布),添加 Codehaus Snapshot 存储库并将版本设置为 1.2-SNAPSHOT(版本 1.2 未在 central 中发布,这应该很快就会发生)(也已在 central 中发布)。pom.xmlgwt.version2.0.0gwt-maven-plugin1.2

  3. 将 添加到 gwt-maven-plugin 配置中,如使用 Google Eclipse 插件中所述。<runTarget>

  4. 配置 maven-war-plugin,如上一步中提到的页面所述。

  5. 通过设置“使用 Google Web 工具包”复选框,从项目首选项中手动启用项目 GWT此步骤是不必要的,因为您将使用 Maven 运行配置构建/运行,而不是 Eclipse 的 GWT 插件。

这就是我的实际样子:pom.xml

<?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">
  <!--
    GWT-Maven archetype generated POM
  -->
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.demo</groupId>
  <artifactId>my-gwtapp</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>gwt-maven-archetype-project</name>

  <properties>

      <!-- convenience to define GWT version in one place -->
      <gwt.version>2.0.0</gwt.version>

      <!--  tell the compiler we can use 1.5 -->
      <maven.compiler.source>1.5</maven.compiler.source>
      <maven.compiler.target>1.5</maven.compiler.target>

  </properties>

  <dependencies>

    <!--  GWT dependencies (from central repo) -->
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <version>${gwt.version}</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <version>${gwt.version}</version>
      <scope>provided</scope>
    </dependency>

    <!-- test -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.4</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <outputDirectory>war/WEB-INF/classes</outputDirectory>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>generateAsync</goal>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <runTarget>com.mycompany.demo.gwt.Application/Application.html</runTarget>
        </configuration>
      </plugin>
      <!--
          If you want to use the target/web.xml file mergewebxml produces,
          tell the war plugin to use it.
          Also, exclude what you want from the final artifact here.
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webXml>target/web.xml</webXml>
                    <warSourceExcludes>.gwt-tmp/**</warSourceExcludes>
                </configuration>
            </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>    
    </plugins>
  </build>

</project>

运行目标(使用 m2eclipse Maven2 >构建...)来设置环境并为 GWT 模块创建启动配置。gwt:eclipse

运行以编译并在 GWT 托管模式下运行 GWT 模块。gwt:compile gwt:run


答案 2

您可以运行以下命令来生成 Maven GWT 项目:

webAppCreator -maven -noant -out

欲了解更多信息:

创建 Maven 项目的 GWT webappcreator:源附件不包含文件 URLClassPath 的源.class


推荐