有没有人有一个样本GWT 2.7.0 pom?

jgp*_*jgp 7 gwt maven

我正在尝试使用Maven和GWT 2.7.0.有没有人有一个小的pom.xml模板?

我特别关注clean/install/running(我在之前的项目中使用gwt:run)...

Tho*_*yer 7

您在POM中需要的是:

  • GWT依赖关系(gwt-user至少,从未部署到服务器; gwt-servlet用于GWT-RPC或其他服务器端支持,gwt-user中已包含的类; gwt-dev和gwt-codeserver是推荐的,它取决于在你将使用的插件上,永远不要部署它们)
  • GWT-行家-插件; 有两个:( org.codehaus.mojo:gwt-maven-plugin其版本必须与您正在使用的版本GWT相匹配),并且net.ltgt.gwt.maven:gwt-maven-plugin(仍处于测试阶段;适用于任何版本的GWT)

根据插件的不同,您将使用不同的打包和插件配置.

最后,但并非最不重要的是,您真的应该为客户端和服务器端代码使用不同的Maven模块,并且可能使用共享代码的第三个模块.但是对于一个小项目,使用单个模块就足够了(但如果您不想在服务器上部署客户端类,则必须向POM添加一些配置/黑客).

对于单模块项目(同一项目中的混合客户端和服务器端代码),我们使用CodeHaus Mojo插件:

<?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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>test</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt</artifactId>
        <version>2.7.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-dev</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-codeserver</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <scope>runtime</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>2.7.0</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <module>com.example.test.Test</module>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
Run Code Online (Sandbox Code Playgroud)

并用于mvn gwt:run运行DevMode(它还将运行您的服务器端代码,但有一些限制).

或者对于net.ltgt插件:

<?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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>test</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>gwt-app</packaging>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt</artifactId>
        <version>2.7.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-dev</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-codeserver</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <scope>runtime</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>net.ltgt.gwt.maven</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>1.0-beta-1</version>
        <extensions>true</extensions>
        <configuration>
          <moduleName>com.example.test.Test</moduleName>
          <launcherDir>${project.build.directory}/${project.build.finalName}</launcherDir>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
Run Code Online (Sandbox Code Playgroud)

并用于mvn gwt:codeserver运行SuperDevMode(仅限客户端代码).您必须使用jetty-maven-plugin或tomcat7-maven-plugin来运行服务器端代码.


对于一个多模块项目,看看我的原型:https://github.com/tbroyer/gwt-maven-archetypes我正在将它们迁移到net.ltgt插件,简化你的方式运行它们(没有必要mvn install了; mvn gwt:codeserver已被设计为多模块项目,违背了Codehaus的Mojo的的gwt:rungwt:run-codeserver)

免责声明:我是两个插件的维护者,但我更喜欢我自己的插件,IMO修复了很多怪癖和错误以及CodeHaus Mojo的遗留问题.