cxhgoo 发表于 2013-1-27 05:00:11

maven2下第一个GWT实例

配置:GWT: 1.5-RC1+ Maven 2.0.9+jboss-4.2.2.GA

下面开始建项目:


在DOS进入选择目录下运行 C:\Documents and Settings\xhchen\Test>mvn archetype:create -DgroupId=com.mycompany -DartifactId=Test -DarchetypeArtifactId=maven-archetype-webapp

在同目录下运行: C:\Documents and Settings\xhchen\Test> applicationCreator com.mycompany.client.index
1.在原文件main新建java/com/mycompany把原文件的client剪切到新建文件下
2.把src下的整个com文件剪切到原resources文件下:即src/main/resources下

Test文件的总目录

|--src
   |--main
       |--java
         |--com
            |--mycompany
                  |--client
                         |--index.java
       |--resources
         |--com
            |--mycompany
                  |--public
                         |--index.css
                         |--index.html
                      |--index.gwt.xml
       |--webapp
            |--WEB-INF
                |--web.xml
               |--index.jsp


配置pom.xml文件,下面是总文件(可用)


<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.mycompany</groupId>
<artifactId>Test</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Test Maven Webapp</name>
<url>http://maven.apache.org</url>

    <repositories>
    <repository>
      <id>gwt-maven</id>
      <url>http://gwt-maven.googlecode.com/svn/trunk/mavenrepo/</url>
    </repository>
    <repository>
      <id>maven</id>
      <url>http://repo1.maven.org/maven2/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
   
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <version>1.5-RC1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <version>1.5-RC1</version>
    </dependency>
   
</dependencies>
<build>
    <finalName>Test</finalName>
<plugins>
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.0</version>
          <configuration>
            <source>1.4</source>
            <target>1.4</target>
          </configuration>
      </plugin>
</plugins>
</build>
<profiles>
      <profile>
          <id>dev</id>
          <build>
            <plugins>
                  <plugin>
                      <groupId>com.totsp.gwt</groupId>
                      <artifactId>maven-googlewebtoolkit2-plugin</artifactId>
                      <version>1.5.1</version>
                      <configuration>
                        <compileTarget>com.mycompany</compileTarget>
                        <logLevel>ALL</logLevel>
                        <gwtVersion>1.5.0</gwtVersion>
                        <runTarget>com.mycompany.index/index.html</runTarget>
                        <generatorRootClasses>com.mycompany.client.index</generatorRootClasses>
                        <!--<overwriteGeneratedClasses>true</overwriteGeneratedClasses>-->
                        <generatorDestinationPackage>com.mycompany.client</generatorDestinationPackage>
                        <generateGettersAndSetters>true</generateGettersAndSetters>
                        <extraJvmArgs>-Xmx512m</extraJvmArgs>
                      </configuration>
                      <executions>
                        <execution>
                              
                        </execution>
                      </executions>
                  </plugin>
            </plugins>
          </build>
      </profile>
</profiles>
</project>


最后,用: mvn com.totsp.gwt:maven-googlewebtoolkit2-plugin:gwt在Hosted mode运行GWT项目,原来就 mvn gwt:gwt 但从十二月份开始总是会下载不到gwt的插件,可能是由于GWT版本的更新,其插件找不到,上面是直接到其插件目录下运行GWT。


最后,如果想把该项目Deploy到jboss(我用的是jboss,不知Tomcat需不需要下面步骤),把index.jsp代码改成
<html>
<body>
<script language="javascript">
    self.location='com.mycompany.index/index.html';
</script>
</body>
</html>

既然其跳转到我们的GWT页面,最后重新build一下,在jboss下运行,就会是和我们Hosted mode 一样的页面,不然只是运行index.jsp,即止打印HelloWorld!







public class Test
{
public static void main(String[] args)
{
    Calendar c = Calendar.getInstance();
    c.set(2007, 11, 29);
   
    for(int i = 0; i < 5; i++)
    {
      System.out.println(c.get(Calendar.WEEK_OF_YEAR) + " " + c.get(Calendar.MONTH));
      c.set(Calendar.WEEK_OF_YEAR, c.get(Calendar.WEEK_OF_YEAR) + 1);
      System.out.println(c.getTime());
    }
}
}

http://www.jspcn.net
http://totos2003.spaces.live.com/default.aspx?_c01_BlogPart=blogmgmt&_c=BlogPart&_c02_owner=1&nextPost=true&postPH=cns!33DDBB259F315EF0!179

http://hi.baidu.com/tblc/blog/item/26e99258e20abfd99c8204d5.html
页: [1]
查看完整版本: maven2下第一个GWT实例