--- --- restore content begins
The first step, start Eclipse, then click open the menu [File] [New] [Other]
Locate the directory Maven, select Maven Project,
Select a Archetype. Here create a Web project, select the maven-archetype-webapp
Enter id
Will generate a maven project. Icon in the top left corner of the project has a letter m
Solve the problem
Once created, a few reported problems.
Solved, open pom.xml, add the following stuff.
1, add plug-ins
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<
plugin
>
<
groupId
>org.apache.maven.plugins</
groupId
>
<
artifactId
>maven-war-plugin</
artifactId
>
<
version
>2.6</
version
>
<
configuration
>
<
failOnMissingWebXml
>false</
failOnMissingWebXml
>
</
configuration
>
</
plugin
>
<
plugin
>
<
groupId
>org.apache.maven.plugins</
groupId
>
<
artifactId
>maven-compiler-plugin</
artifactId
>
<
version
>3.1</
version
>
<
configuration
>
<
source
>1.8</
source
>
<
target
>1.8</
target
>
</
configuration
>
</
plugin
|
2, dependent added serlvet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<
dependency
>
<
groupId
>javax.servlet</
groupId
>
<
artifactId
>javax.servlet-api</
artifactId
>
<
version
>3.1.0</
version
>
</
dependency
>
<
dependency
>
<
groupId
>javax.servlet.jsp</
groupId
>
<
artifactId
>javax.servlet.jsp-api</
artifactId
>
<
version
>2.3.1</
version
>
</
dependency
>
<
dependency
>
<
groupId
>javax.servlet</
groupId
>
<
artifactId
>jstl</
artifactId
>
<
version
>1.2</
version
>
</
dependency
>
|
Complete pom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
<
modelVersion
>4.0.0</
modelVersion
>
<
groupId
>com.liyongzhen</
groupId
>
<
artifactId
>myweb</
artifactId
>
<
packaging
>war</
packaging
>
<
version
>0.0.1-SNAPSHOT</
version
>
<
name
>myweb Maven Webapp</
name
>
<
dependencies
>
<
dependency
>
<
groupId
>javax.servlet</
groupId
>
<
artifactId
>javax.servlet-api</
artifactId
>
<
version
>3.1.0</
version
>
</
dependency
>
<
dependency
>
<
groupId
>javax.servlet.jsp</
groupId
>
<
artifactId
>javax.servlet.jsp-api</
artifactId
>
<
version
>2.3.1</
version
>
</
dependency
>
<
dependency
>
<
groupId
>javax.servlet</
groupId
>
<
artifactId
>jstl</
artifactId
>
<
version
>1.2</
version
>
</
dependency
>
<
dependency
>
<
groupId
>junit</
groupId
>
<
artifactId
>junit</
artifactId
>
<
version
>3.8.1</
version
>
<
scope
>test</
scope
>
</
dependency
>
</
dependencies
>
<
build
>
<
finalName
>myweb</
finalName
>
<
plugins
>
<
plugin
>
<
groupId
>org.apache.maven.plugins</
groupId
>
<
artifactId
>maven-war-plugin</
artifactId
>
<
version
>2.6</
version
>
<
configuration
>
<
failOnMissingWebXml
>false</
failOnMissingWebXml
>
</
configuration
>
</
plugin
>
<
plugin
>
<
groupId
>org.apache.maven.plugins</
groupId
>
<
artifactId
>maven-compiler-plugin</
artifactId
>
<
version
>3.1</
version
>
<
configuration
>
<
source
>1.8</
source
>
<
target
>1.8</
target
>
</
configuration
>
</
plugin
>
</
plugins
>
</
build
>
</
project
>
|
调整Servlet版本
当前主流Servlet开发或者说主流Java Web开发,Servlet的版本是3.1。(Servlet 4.0还未被大量采用)。
我们在添加依赖时,Servlet版本也是3.1,而maven工程创建时Servlet是2.3
右击工程名,在弹出的菜单中选择【Properties】
弹出对话框,选择【Project Facets】
找到 Dynamice Web Module,去掉前面勾选
将Serlvet版本更改为3.1,再点击【Apply】
最后点击【Apply and Close】
再看,更新过来。