Maven
为啥用Maven
-
在web开发中需要很多的jar 包手动很不方便
-
Maven可以自动帮我导入和配置这个jar包
-
只是一个工具
-
Maven 项目架构管理的工具
目前就时简单的导包
核心思想:约定大于配置
-
有约束,不要去违反
-
maven 会规定如何去编写我们的java代码
下载
在环境变量中
-
M2_HOME maven 目录下的bin目录
-
MAVEN_HOME maven 目录
-
在系统path中配置 %MAVEN_HOME%\bin
-
表示成功了
-
配置阿里云的镜像提供 速度
-
镜像 mirrors
-
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
<--!--> 放在 <mirror></mirror> 里
Idea 中使用maven
-
选择模板 webapps
-
选择maven路径
-
选择maven本地仓库
为了防止每次都需要改防止使用错仓库 可以在 new-> new project setting-> setting for New projects> maven -> 调整xml setting位置和仓库位置 这样下次创建新的项目就不用手动更改了
-
配置 Tomcat
Maven 资源导出问题
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.xml</exclude>
</excludes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
替换webapp版本
在 tomcat 里root 找到
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"
metadata-complete="true">
</web-app>