maven构建第一个项目

来源:互联网 发布:tensorflow 路径规划 编辑:程序博客网 时间:2024/05/21 04:23

1.新建Maven项目

2.调过骨架,如果不跳过骨架选择创建出的项目目录是不全的

3. 填写坐标


4.手动在webapp文件夹下创建一个WEB-INF文件夹,在里面放一个web.xml文件

5.处理编译版本

在pom.xml中添加如下代码

<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.5.1</version>  <configuration><source>1.7</source><target>1.7</target><encoding>UTF-8</encoding></configuration></plugin></plugins></build>
5.创建一个servlet

6.添加jar包

在pom中添加如下代码:

<dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.9</version><scope>test</scope></dependency><dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>2.5</version><scope>provided</scope></dependency><dependency><groupId>javax.servlet</groupId><artifactId>jsp-api</artifactId><version>2.0</version><scope>provided</scope></dependency></dependencies>
7..启动项目

 右击项目---run as –maven build ….           tomcat:run



注意点:

1.建立本地仓库索引,方便添加jar包

2.依赖范围:

1.Compile    struts-core

编译(compile)时需要测试时需要,,运行时需要,打包时需要

2.Provided    jsp-api.jar

编译(compile)时需要,测试(test)时也需要 ,运行时不需要,打包时不需要

3.Runtime   数据库驱动包

编译时不需要,测试时需要,运行时需要,打包时需要

4.Test     junit.jar

编译时不需要,测试时需要,运行时不需要,打包也不需要





                           




原创粉丝点击