maven学习笔记(定制一个Web项目)

时间:2022-01-03 12:02:26

创建web项目:

mvn archetype:generate -DgroupId=cn.net.comsys.ut4.simpleweb -DartifactId=simple-web -DpackageName=cn.net.comsys.ut4.simpleweb -Dversion=1.0 -DarchetypeArtifactId=maven-archetype-webapp  -DinteractiveMode=false

向pom.xml添加jetty依赖

  <build>
<finalName>simple-web</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>

jetty插件的run目标启动web项目:

mvn jetty:run

  

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>cn.net.comsys.ut4.simpleweb</groupId>
<artifactId>simple-web</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>simple-web Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>6.1.26</version>
</dependency> </dependencies>
<build>
<finalName>simple-web</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
</plugin>
</plugins>
</build>
</project>

添加J2EE依赖:

	<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<version>1.0</version>
</dependency>
mvn clean install
mvn jetty:run