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.
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。