注意,以下所有需要建立在你的eclipse等已经集成配置好了maven了,没有的话需要安装maven。

一、创建项目

1.新建maven项目,如果不在上面,请到other里面去找一下

eclipse 创建maven web示例

 

一直点击下一步,到选择webapp之后  next

 eclipse 创建maven web示例

eclipse 创建maven web示例

点击finish,会生成一个这样目录的项目

 eclipse 创建maven web示例

二、配置maven

 1)首先新建几个文件夹

    src/main/java

    src/test/java 

    src/test/resources三个文件夹

右键项目根目录点击New -> Source Folder,

建出这三个文件夹。注意不是建普通的Folder,而是Source Folder

eclipse 创建maven web示例

如果出现了这情况,其实是真的存在的只是我们看不到

2)项目右键属性

eclipse 创建maven web示例

eclipse 创建maven web示例

切换成这样子就好了

eclipse 创建maven web示例

目前目录还缺少src/test/resources继续新建还没有的、新建完成

eclipse 创建maven web示例

2)更改class路径

右键项目,Java Build Path -> Source

下面应该有4个文件夹。src/main/java,src/main/resources,src/test/java ,src/test/resources。

双击每个文件夹的Output folder,选择路径。

src/main/java,src/main/resources,选择target/classes;

src/test/java ,src/test/resources, 选择target/test-classes;

选上Allow output folders for source folders

eclipse 创建maven web示例

此处还可以更改显示顺序

eclipse 创建maven web示例

3)更改Dynamic Web Module 版本,发现切换成3.0发现报错

eclipse 创建maven web示例

因为新建项目的时候,用了maven-artchetype-webapp

由于这个catalog比较老,用的servlet还是2.3的

 eclipse 创建maven web示例

修改成

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<web-app>
  <display-name>Archetype Created Web Application</display-name>
</web-app>

进入Navigator 

eclipse 创建maven web示例

 

还需要修改两个文件,

eclipse 创建maven web示例

 eclipse 创建maven web示例

修改成

eclipse 创建maven web示例

eclipse 创建maven web示例

重新打开属性 project Facets,看到这个地方已经修改成3.0

eclipse 创建maven web示例

三、部署tomcat

我未采用tomcat7的maven插件,网上很多可以去自己实际配置。

eclipse 创建maven web示例

eclipse 创建maven web示例

启动下

eclipse 创建maven web示例

搭建完成。

 

相关文章:

  • 2021-07-13
  • 2021-08-13
  • 2021-08-09
  • 2021-07-22
猜你喜欢
  • 2021-11-07
  • 2022-02-15
  • 2022-01-10
  • 2021-07-13
  • 2021-11-17
  • 2021-05-13
  • 2021-11-24
相关资源
相似解决方案