在gwt项目中使用maven的方法
gwt默认是使用ant脚本的。但是我们的项目都十分依赖maven,因为maven实在是太方便了。
在gwt项目中使用maven并不难,主要是使用这个插件:
目录结构和ant或者eclipse gwt插件稍有不同:
所有java文件采用的是maven惯用目录结构,但是web部分,使用ant和eclipse gwt插件约定的结构,这样是为了能使用到gwt eclipse插件。
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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.easymorse</groupId>
<artifactId>standard.console</artifactId>
<packaging>war</packaging>
<version>1.1</version>
<name>standard.console</name><properties>
<gwt.version>2.0.0</gwt.version>
</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-user</artifactId>
<version>${gwt.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</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>
<configuration>
<runTarget>Standard_console.html</runTarget>
</configuration><executions>
<execution>
<goals>
<goal>compile</goal>
<goal>generateAsync</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
我目前的项目是手工生成的,可以将项目原型化,然后做成自定义的archetype。
项目生成后,可以:
mvn eclipse:eclipse gwt:eclipse
生成eclipse项目。导入方式和web项目类似。
如果不想在eclipse中使用gwt插件,调试可以命令行执行:
mvn gwt:run
效果和eclipse gwt插件类似。如果想用eclipse gwt插件,需要设置项目的:
然后,勾选:
这样,就可以通过debug,在gwt插件中运行项目了。
这篇文章上的评论的 RSS feed TrackBack URI