posts - 6, comments - 0, trackbacks - 0, articles - 0

2011年3月16日

%date:~0,10% %time:~0,8%
日期格式
2011-03-17 11:38:06



posted @ 2011-03-17 11:43 rainingcn 阅读(410) | 评论 (0)编辑 收藏

1. 使用Maven的maven-archetype-webapp 创建

mvn archetype:create -DgroupId=com.test -DartifactId=tutorial -DarchetypeArtifactId=maven-archetype-webapp
2.修改pom.xml。在build属性中增加jetty配置
<build>
    
<finalName>tutorial</finalName>
    
<plugins>
         
<plugin>
              
<groupId>org.mortbay.jetty</groupId>
              
<artifactId>maven-jetty-plugin</artifactId>
         
</plugin>
        
<!--
        
<plugin>               
            
<groupId>org.codehaus.mojo</groupId>               
            
<artifactId>tomcat-maven-plugin</artifactId>
        
</plugin>
        
-->
     
</plugins>
  
</build>
   2.1 可以输入 mvn jetty:run  启动jetty容器
3.增加struts2相关配置。具体的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.test</groupId>
  
<artifactId>tutorial</artifactId>
  
<packaging>war</packaging>
  
<version>1.0-SNAPSHOT</version>
  
<name>tutorial Maven Webapp</name>
  
<dependencies>
    
<dependency>
      
<groupId>junit</groupId>
      
<artifactId>junit</artifactId>
      
<version>4.8.1</version>
      
<scope>test</scope>
    
</dependency>
    
<dependency>
        
<groupId>org.apache.struts</groupId>
        
<artifactId>struts2-core</artifactId>
        
<version>2.2.1</version>
    
</dependency>

    
<dependency>
        
<groupId>log4j</groupId>
        
<artifactId>log4j</artifactId>
        
<version>1.2.14</version>
    
</dependency>
    
<dependency>
        
<groupId>javassist</groupId>
        
<artifactId>javassist</artifactId>
        
<version>3.8.0.GA</version>
    
</dependency>
  
</dependencies>
  
<build>
    
<finalName>tutorial</finalName>
    
<plugins>
         
<plugin>
              
<groupId>org.mortbay.jetty</groupId>
              
<artifactId>maven-jetty-plugin</artifactId>
         
</plugin>
        
<!--
        <plugin>               
            <groupId>org.codehaus.mojo</groupId>               
            <artifactId>tomcat-maven-plugin</artifactId>
        </plugin>
        
-->
     
</plugins>
  
</build>
</project>

4.导入到相关的IDE工具。如idea
mvn idea:idea
   4.1 idea中的目录结构

5.写个class 看下能否正常跳转。注意点:java类的源目录为
src
│  └─main
│      ├─java
public class Test {
    public String execute() {
        return "success";
    }
}
对应的struts.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd"
>

<struts>
    
<package name="default" extends="struts-default" namespace="/">
        
<action name="test" class="com.test.Test">
            
<result>index.jsp</result>
        
</action>
    
</package>
</struts>
6. url: http://localhost:8080/test

7.参考:
  

Building Web Applications with Maven 2

Create Struts 2 Web Application Using Maven To Manage Artifacts and To Build The Application
 

posted @ 2011-03-16 15:02 rainingcn 阅读(1566) | 评论 (0)编辑 收藏