注:本文章用来做记录,是根据各大佬的文章参考的,如发现抄袭,望谅解
一、基本信息
JDK:1.8.0_191 命令:java -version
maven:3.9.1
eclipse:2017
一、配置maven
1、下载
2、配置(eclipse)
1、准备材料
解压前面下载的maven,放在不经常打开的文件夹中
创建一个仓库(本地仓库),就是文件夹,存放jar
配置本地仓库地址:D:\UnzipVersion\apache-maven-3.9.1\conf的settings.xml配置文件
警告:记得配置阿里云代理仓库,不然后面点击创建maven项目,直接卡死(因为本地仓库什么jar都没有,之前去外网下载一些jar)
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
2、进入maven配置
是:D:\UnzipVersion\apache-maven-3.9.1\conf的settings.xml配置文件
如果,没有自动生成本地仓库地址,看看有没有配置了本地仓库地址(前面的2-1)
或者,配置了,没有生成,那再来【】添加settings,xml试试
最后,记得Apply保存
三、Eclipse使用maven创建javaweb
1、创建maven项目(javaweb)
1、是Maven Project
记得勾上:不勾上,骨架模板创建,是少了一些文件的,自己可以试试
勾上:跳过骨架模板
next
选择war,创建javaweb,点击finish
不执行 通过,这里可以看出,骨架模板少了一些
不执行 骨架模板介绍
2、创建maven后,还要修改一些配置
1、浏览模式
2、显示
3、先看pom.xml报错
原因:创建javaweb项目,少了web.xml
创建WEB-INF
在创建web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
4、解析各种文件
5、处理jdk版本问题
注:这个1.8,看自己jdk版本,还有前面下载的maven看一下合不合适,如果跟我的一样话,就继续跟着吧
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
保存
再右键项目,maven-->update-project
最后,变成1.8
3、添加依赖(jar)(pom.xml)
1、配置添加
<!-- 添加maven 依赖坐标 -->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<!-- ... -->
</dependencies>
maven依赖查找地址
不需要依赖jar,直接删除,生成的那个文件夹里面就没有改jar包,如果全部删除,文件夹都删除了
2、手动添加
(1)在pom.xml右键,或者在pom.xml里面右键都可以
(2)输入可用id或者模块id
输入servlet,是没有的,但是输入junit是有的,因为仓库里没有
但是,如果创建仓库放入一些jar,也显示不出来,需要刷新
添加,
刷新
4、运行
命令:tomcat:run
注:这里,是测试,我没有配置web那些,
注:
自己添加ssm,不然,一直运行,有点问题