本文主要介绍如何使用Maven快速构建GWT项目。(本文假定你对GWT、Maven都有过一定了解)
LZ使用如下环境:
C:\Users\Administrator>mvn -version
Apache Maven 2.2.1 (r801777; 2009-08-06 20:16:01+0100)
Java version: 1.6.0_18
Java home: D:\install\dev\Java\jdk1.6.0_18\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 7" version: "6.1" arch: "x86" Family: "windows"
Eclipse 3.6、GWT 2.1.1
Step 1:创建GWT项目
mvn archetype:generate -DarchetypeRepository=repo1.maven.org -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.1.1-SNAPSHOT
使用Maven创建的GWT工程包结构如下图所示:
http://www.yupoo.com/photos/brofe/79719131/
Step 2:修改 pom.xml, 添加其它所需依赖,LZ使用内嵌的 Jetty 7 故完整的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.brofe.gwt.samples</groupId>
<artifactId>gwt-samples</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>GWT Maven Archetype</name>
<properties>
<!-- Convenience property to set the GWT version -->
<gwt.version>2.1.1</gwt.version>
<jetty.version>7.2.2.v20101205</jetty.version>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
</properties>
<dependencies>
<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-servlet-deps</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>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>${gwt.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<!-- jetty -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-start</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jsp-2.1</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1-glassfish</artifactId>
<version>2.1.v20100127</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- jetty end -->
</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.1.1-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<!--<goal>i18n</goal> 表示不自动生成国际化类-->
<!--<goal>generateAsync 表示不自动生成RPC异步类</goal>-->
</goals>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see gwt-maven-plugin documentation at codehaus.org -->
<configuration>
<runTarget>GWTSamples.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<i18nMessagesBundle>com.brofe.gwt.samples.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>
Step 3:将gwt-samples项目转化成Eclipse项目:
mvn eclipse:eclipse
Step 4: 编写启动 Jetty 服务的类:
/**
* $Id: StartGWTSamplesJetty.java, 2011-2-6 下午11:55:43, brofe Exp $
*/
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
/**
* @author <a href="brofe.pan@gmail.com">brofe</a>
* @since 2011-2-6 下午11:55:53
* @version v 1.0
*/
public class StartGWTSamplesJetty {
protected int port = 8088;
protected String webapp = "gwt-samples-1.0";
protected String deployPath = "./target/" + webapp;
public static void main(String[] args) throws Exception {
StartGWTSamplesJetty jetty = new StartGWTSamplesJetty();
jetty.init();
jetty.run();
}
protected void init() {
}
protected void run() throws Exception {
Server server = new Server(this.port);
WebAppContext context = new WebAppContext();
context.setDescriptor(this.webapp + "/WEB-INF/web.xml");
context.setResourceBase(deployPath);
context.setContextPath("/");
context.setParentLoaderPriority(true);
server.setHandler(context);
server.start();
server.join();
}
}
Step 5:使用Maven编译gwt-samples,编译结果在:“target/gwt-samples-1.0/GWTSamples”目录
mvn gwt:compile
Step 6:运行StartGWTSamplesJetty.java,然后在浏览器中(http://localhost:8088)即可访问
Step 7:在 Eclipse Debug Configurations 中配置GWT调试模式,并且使用自己的Jetty服务器,而不是GWT调试模式自带的服务器,详情看如下截图
1、
http://www.yupoo.com/photos/brofe/79719127/
2、
http://www.yupoo.com/photos/brofe/79719128/
-war target/gwt-samples-1.0 -startupUrl GWTSamples.html com.brofe.gwt.samples.GWTSamples -noserver -port 8088
3、
http://www.yupoo.com/photos/brofe/79719130/
Step 8:启动调试
1、先 Debug 运行:StartGWTSamplesJetty.java
2、再 Debug 运行刚才配置的DevMode:GWTSamples-Debug
3、然后浏览器中访问:http://localhost:8088,即可单步调试GWT程序。
Step 9:使用Maven打包发布,发布包会在target目录下
mvn war:war
其它:关于 Maven GWT Plugin 其它Goals,有兴趣的同学可以试试,比如mvn:gwt:run,详情见:
http://mojo.codehaus.org/gwt-maven-plugin/plugin-info.html
由于Img标签貌似用不好,所以其中图片都是用URL的方式,如果有会用的同学请教教我。
本文完。
分享到:
相关推荐
该插件旨在通过提供两种特定的打包方式: gwt-lib和gwt-app ,使使用Maven构建GWT项目更加容易。 基本用法 将插件添加到您的POM并启用扩展: < plugin> < groupId>net.ltgt.gwt.maven</ groupId> < artifactId>...
现在,该插件被认为是legacy GWT maven plugin (又名mojo GWT maven插件),而新插件被认为是new generation GWT maven plugin (又名tbroyer GWT maven插件)。 仍然支持旧版maven插件,但强烈建议将新插件用于新...
一、在环境变量中创建以下配置 1、 变量名:JAVA_HOME 变量值:D:\Java\jdk1.6.0_02 变量注:这个变量是指定JDK放的位置,变量的值与JAVA根目录的路径对应 2、 变量名:TOMCAT_HOME 变量值:D:\project tools\...
maven-gwt-plugin-1.5.0.jar
maven-gwt-plugin-1.0.jar
maven-gwt-plugin-1.0.2.jar
maven-gwt-plugin-1.0.1.jar
maven-gwt-plugin-1.5.0-sources.jar
maven-gwt-plugin-1.0-sources.jar
maven-gwt-plugin-1.0.2-sources.jar
maven-gwt-plugin-1.0.1-sources.jar
(JDK1.6, Maven 3.0, GWT2.1.1,...gwt maven plugin 创建的 SmartGwt 项目,实现中文、英文国际化。 相关介绍在:http://blog.csdn.net/usedtolove/archive/2011/02/23/6201391.aspx 请选择作为 Maven 项目导入到 IDE。
GWT Maven插件的文档位于: :
angulargwt.zip,gwt angularjs集成gwtangularjs集成gwt
使用的技术: IDE:eclipse Luna Service Release 2 (4.4.2) Jar 管理:Apache Maven Web 技术:GWT、GWTP、CSS 版本 GWT 版本:2.7.0 gwt-maven-plugin.version:2.7.0 目标.jdk:1.7
为了能够编译为JavaScript,您需要添加gwt-maven-plugin并添加您的GWT模块名称。 < groupId>com.github.gwtboot</ groupId> < artifactId>gwt-boot-starter-parent < version>VERSION</ ver
<dependency><groupId>com.github.neothemachine</groupId><artifactId>gwt-webdriver-junit-runstyle</artifactId><version>0.0.1-SNAPSHOT</version><scope>test</scope></dependency>调整gwt-maven-plugin使用的...
gwt-maven-plugin.zip,用mavenst重新开始构建gwt项目用maven重新开始构建gwt项目