maven创建web项目

创建web应用程序

命令模板:

mvn archetype:generate -DgroupId={project-packaging} -DartifactId={project-name} -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

如:
mvn archetype:generate -DgroupId=com.project -DartifactId=Project -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

修改pom.xml确定jar包依赖
如:

 

<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.project</groupId> 
<artifactId>Project</artifactId> 
<packaging>war</packaging> 
<version>1.0-SNAPSHOT</version> 
<name>Project Maven Webapp</name> 
<url>http://maven.apache.org</url> 
<properties> 
<spring.version>3.0.5.RELEASE</spring.version> 
<junit.version>4.11</junit.version> 
<jdk.version>1.6</jdk.version> 
</properties> 
<dependencies> 
<!-- Spring 3 dependencies --> 
<dependency> 
<groupId>org.springframework</groupId> 
<artifactId>spring-core</artifactId> 
<version>${spring.version}</version> 
</dependency> 
<dependency> 
<groupId>org.springframework</groupId> 
<artifactId>spring-web</artifactId> 
<version>${spring.version}</version> 
</dependency> 
<dependency> 
<groupId>org.springframework</groupId> 
<artifactId>spring-webmvc</artifactId> 
<version>${spring.version}</version> 
</dependency> 
<dependency> 
<groupId>junit</groupId> 
<artifactId>junit</artifactId> 
<version>${junit.version}</version> 
<scope>test</scope> 
</dependency> 
</dependencies> 
<build> 
<finalName>Project</finalName> 
</build> 
</project>



运行命令mvn compile编译
或mvn package打war包

项目目录结构:
Project
├─src 
│ └─main 
│      ├─resources 
│      └─webapp 
│           └─WEB-INF 
└─target 
     ├─classes 
     ├─maven-archiver 
     └─Project 
          ├─META-INF 
          └─WEB-INF 
               ├─classes 
               └─lib

target目录下包含Project.war文件,文件里的lib目录包含所以来的jar包

>> End.

 

补充:

maven下载源码和javadoc方法:

1. 通过命令下载:

mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc

2. .m2/settings.xml增加如下配置:

<profiles>
<profile>
    <id>downloadSources</id>
    <properties>
        <downloadSources>true</downloadSources>
        <downloadJavadocs>true</downloadJavadocs>           
    </properties>
</profile>
</profiles>

<activeProfiles>
  <activeProfile>downloadSources</activeProfile>
</activeProfiles>

3. IDE配置

posted @ 2014-02-25 00:06  wouldguan  阅读(194)  评论(0编辑  收藏  举报