4.Maven项目的创建
4.1创建java项目
4.1.1 新建项目
创建resources目录
利用maven命令去编译这个项目
利用maven命令去打包
4.2创建web项目
4.2.1 新建项目
新建web项目和创建java项目基本一致,区别在于选择Maven模板(web项目选择webapp),如图
4.2.2 启动项目
6.2.2.1 修改jdk的版本
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
6.2.2.2 设置单元测试的版本
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
6.2.2.3 删除pluginManagement标签
<!--将这个标签以及标签中的内容全部删除-->
<pluginManagement>
.....
</pluginManagement>
6.2.2.4添加web部署插件
在build标签中添加plugins标签
下面俩放在
1.Jetty插件
<!-- 设置在plugins标准中 -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.11.v20150529</version>
<configuration>
<!--热部署,每10秒扫描一次-->
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<!--可指定当前项目的站点名-->
<contextPath>/test</contextPath>
</webApp>
<httpConnector>
<port>9090</port> <!--设定端口号-->
</httpConnector>
</configuration>
</plugin>
2.Tomcat插件
<!-- Tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!--配置端口号-->
<port>80</port>
<!--配置项目路径-->
<path>/mavenWeb</path>
</configuration>
</plugin>
6.2.2.5 启动项目
点击右上角的 “Add Configurations”,打开“Run/Dedug Configurations”窗口
1.jetty启动
访问路径
http://localhost:9090/test/index.jsp
2.tomcat启动
访问路径
http://localhost/mavenWeb/index.jsp