Maven具体配置-从安装到工程创建

setting.xml

<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
	<!--本地的jar包路径 -->
  <localRepository>D:/Tools/repository</localRepository>
  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
  <!--  <mirror>
      <id>maven-default-http-blocker</id>
      <mirrorOf>external:http:*</mirrorOf>
      <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
      <url>http://0.0.0.0/</url>
      <blocked>true</blocked>
    </mirror>
	-->
	 <!-- 阿里云仓库 -->
	 
	    <mirror>
		<id>huaweicloud</id>
		<mirrorOf>*</mirrorOf>
        <url>http://marrors.huaweicloud.com/repository/maven/</url>
	 </mirror>
		
		
	 
      <mirror>
            <id>central</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>https://maven.aliyun.com/repository/central/</url>
        </mirror>
	

    
   
  </mirrors>

  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>

      <activation>
        <jdk>1.4</jdk>
      </activation>

      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->

    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>

      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>

      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
  </profiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

一、为什么要使用maven

1.项目管理问题:项目中jar包资源越来越多,jar包的管理越来越沉重。

2.繁琐:要为每个项目手动导入所需的jar,需要搜集全部jar

3.复杂:项目中的jar如果需要版本升级,就需要再重新搜集jar

4.冗余:相同的jar在不同的项目中保存了多份

5.java项目需要一个统一的便捷的管理工具:Maven
在这里插入图片描述

二、maven的好处

2.1 mvn 自动化构建(自动化装配)

没有自动化构建

在这里插入图片描述
当有了自动化构建之后
在这里插入图片描述

2.2 和对jar包的管理

maven就是用java来写的,专注为java服务,提供便利

三、Maven安装

3.1 下载Maven

| http://us.mirrors.quenda.co/apache/maven/maven-3/3.5.4/binaries/ |

3.2 Maven安装
3.2.1 解压

注意: 解压文件尽量不要放在含有中文或者特殊字符的目录下。

解压后,有如下目录:

`bin:含有mvn运行的脚本`
`boot:含有plexus-classworlds类加载器框架,Maven 使用该框架加载自己的类库。`
`conf:含有settings.xml配置文件`
`lib:含有Maven运行时所需要的java类库`
3.2.2 环境变量

注意(配置maven环境之前必须先配置java的环境变量再去配置maven的环境变量):maven依赖java环境,所以要确保java环境已配置好 (maven-3.3+ 需要jdk7+)

maven本身有2个环境变量要配置:

`MAVEN_HOME = maven的安装目录`
`PATH = maven的安装目录下的bin目录`

第一步:
在这里插入图片描述
第二步:
在这里插入图片描述

第三步:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

配置完成之后doc测试成功
在这里插入图片描述

四、Maven配置


4.1 本地仓库

maven的conf目录中有 settings.xml ,是maven的配置文件,做如下配置:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 			  	http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <!-- 选择一个磁盘目录,作为本地仓库 -->
  <localRepository>D:\Program Files\maven\myrepository</localRepository>
4.2 JDK配置

标签中 增加 一个 标签,限定maven项目默认的jdk版本.

内容如下:

<profile>
		<id>jdk-1.8</id>
		<activation>
			<activeByDefault>true</activeByDefault>
			<jdk>1.8</jdk>
		</activation>
		<properties>
			<Maven.compiler.source>1.8</Maven.compiler.source>
			<Maven.compiler.target>1.8</Maven.compiler.target>
			<Maven.compiler.compilerVersion>1.8</Maven.compiler.compilerVersion>
		</properties>
	</profile>
4.3 配置tomcat

注意点:由于maven中央仓库中没有tomcat8镜像,只有tomcat7 但是在idea中可以直接使用tomcat8

在这里插入图片描述

   <server>  
     <id>tomcat7</id>  
     <username>tomcat</username>  
      <password>tomcat</password>
 </server>

4.4 配置配置阿里镜像(进入阿里云的仓库去下载镜像)

在这里插入图片描述
ps:

  <mirror>
        <id>central</id>
        <mirrorOf>central</mirrorOf>
        <name>aliyun maven</name>
        <url>https://maven.aliyun.com/repository/central/</url>
    </mirror>

五、仓库


5.1 概念
  • 存储依赖的地方,体现形式就是本地的一个目录。
  • 仓库中不仅存放依赖,而且管理着每个依赖的唯一标识(坐标),Java项目凭坐标获取依赖。
  • 存储jar的仓库,通过坐标来获取仓库中的jar
5.2 仓库分类

仓库分类如下:
在这里插入图片描述

当需要依赖时,会从仓库中取查找,优先顺序为:

本地仓库 > 私服(如果配置了的话,基本公司都会有,所有进公司的第一天记得找运维要私服哦) > 公共仓库(如果配置了的话) > 中央仓库

5.3 本地仓库

即在settings.xml 中配置的目录。

使用过了的依赖都会自动存储在本地仓库中,后续可以复用。

5.4 远程仓库
5.4.1 中央仓库
  • Maven 中央仓库是由 Maven 社区提供的仓库,不用任何配置,maven中内置了中央仓库的地址。

    其中包含了绝大多数流行的开源Java构件。

  • https://mvnrepository.com/ 可以搜索需要的依赖的相关信息(仓库搜索服务)

    http://repo.maven.apache.org/maven2/ 中央仓库地址

5.4.2 公共仓库【重点
  • 除中央仓库之外,还有其他远程仓库。
    比如aliyun仓库(http://maven.aliyun.com/nexus/content/groups/public/)

  • 中央仓库在国外,下载依赖速度过慢,所以都会配置一个国内的公共仓库替代中央仓库。

<!--setting.xml中添加如下配置-->
  <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>   

      <mirror>
    <id>huaweicloud</id>
	 <mirrorOf>*</mirrorOf>         
    <url>https://mirrors.huaweicloud.com/repository/maven/</url> 
 </mirror>
5.4.3 私服【了解】

公司范围内共享的仓库,不对外开放。

可以通过 Nexus来创建、管理一个私服。

六、Idea-Maven


6.1 在Idea中关联Maven

在idea中关联本地安装的maven,后续就可以通过idea使用maven,管理项目啦。

设置全局关联

在这里插入图片描述

6.2 创建Maven项目
6.2.1 新建项目(不用模板的创建方式)

在这里插入图片描述

6.2.2 指定项目名

在这里插入图片描述

6.2.3 项目位置

在这里插入图片描述

maven的刷新
在这里插入图片描述

6.2.4 项目结构
  • src/main/java 存放源代码,建包,放项目中代码(service,dao,User,…)

  • src/main/resources 书写配置文件,项目中的配置文件(jdbc.properties)

  • src/test/java 书写测试代码,项目中测试案例代码

  • src/test/resources 书写测试案例相关配置文件

  • 目根/pom.xml (project object model) maven项目核心文件,其中定义项目构建方式,声明依赖等

  • 注意:项目中的建包,建类,执行,都和普通项目无差异

在这里插入图片描述

6.2.5 项目类型

根据项目类型,在pom.xml中做出对应配置,添加配置:war/jar

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.qf</groupId>
    <artifactId>test01</artifactId>
    <version>1.0-SNAPSHOT</version>
    <!-- 打包方式,如果是java项目则用 jar,
         如果是web项目则用war -->
    <!--<packaging>war</packaging>-->
    <packaging>jar</packaging>
</project>
6.2.5.1 使用idea中插件快速创建web项目
6.2.5.2 手动创建web项目
6.3 导入依赖jar

建好项目后,需要导入需要的jar,要通过坐标

  • 每个构件都有自己的坐标 = groupId + artifactId + version = 项目标识 + 项目名 + 版本号

  • 在maven项目中只需要配置坐标,maven便会自动加载对应依赖。删除坐标则会移除依赖

6.3.1 查找依赖

依赖查找服务:https://mvnrepository.com/ ,获得依赖的坐标,在maven项目中导入。

在这里插入图片描述

具体要拷贝的东西
在这里插入图片描述

6.3.2 导入依赖

在项目的pom文件中,增加依赖

在这里插入图片描述

6.3.3 同步依赖

引入坐标后,同步依赖,确认导入。
在这里插入图片描述

####6.4 创建web项目

6.4.1 打包方式
1.jar 普通的Java jar  打包之后提供给其他使用
2.war  web项目jar
3.pom  一般用于实际开发中作为父工程使用

在这里插入图片描述

两种打包的区别

war模式:将WEB工程以包的形式上传到服务器 ;
war exploded模式:将WEB工程以当前文件夹的位置关系上传到服务器;
A.war模式这种可以称之为是发布模式,看名字也知道,这是先打成war包,再发布;

B.war exploded模式是直接把文件夹、jsp页面 、classes等等移到Tomcat 部署文件夹里面,进行加载部署。因此这种方式支持热部署,一般在开发的时候也是用这种方式。

C.在平时开发的时候,使用热部署的话,应该对Tomcat进行相应的设置,这样的话修改的jsp界面什么的东西才可以及时的显示出来。

设置热部署
在这里插入图片描述

web项目打包方式为:war
在这里插入图片描述
6.4.2 web依赖

导入 JSPServletJSTL依赖,使项目具有web编译环境

<?xml version="1.0" encoding="UTF-8"?>
<project ...>
    ...
    <packaging>war</packaging>

	<!-- 导入JSP 和 Servlet 和 JSTL 依赖 -->
    <dependencies>
        <dependency>
            <!-- jstl 支持 -->
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <!-- servlet编译环境 -->
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <!-- jsp编译环境 -->
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>
6.4.3 webapp目录

按照maven规范,新建web项目特有目录

   新建如下目录和文件       

在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>
<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">
	<!-- 这是一个空白的web.xml文件模板 -->
</web-app>
6.4.4 定义Servlet和Jsp

在这里插入图片描述

6.5 部署web项目
6.5.1 新增Tomcat
新增Tomcat

第一步在这里插入图片描述

第二步

在这里插入图片描述

第三步
在这里插入图片描述

6.5.2 部署web项目

| 部署web项目 |
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

6.5.3 启动Tomcat

| 启动Tomcat |
在这里插入图片描述
在这里插入图片描述

6.6 依赖生命周期
6.6.1 概念

Jar包生效的时间段,即Jar的生命周期

6.6.2 使用方式

项目中导入的依赖可以做生命周期的管理

<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.6</version>
    <!-- 生命周期 -->
    <scope>compile</scope>
</dependency>
<dependency>
    <!-- servlet编译环境 -->
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <!-- 生命周期 -->
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <!-- 生命周期 -->
    <scope>test</scope>
</dependency>
6.6.3 生命周期详解
标识周期
compile缺省值,适用于所有阶段(测试运行,编译,运行,打包)
provided类似compile,期望JDK、容器或使用者会提供这个依赖。如servlet-api.jar;适用于(测试运行,编译)阶段
runtime只在运行时使用,如 mysql的驱动jar,适用于(运行,测试运行)阶段
test只在测试时使用,适用于(编译,测试运行)阶段,如 junit.jar

注意点

在编译和测试过程中有效,最后生成的war包时不会加入 例如:
servlet-api,因为servlet-api tomcat服务器已经存在了,如果再打包会冲突

七、Maven指令


7.1 命令行
mvn  compile  是构建主程序的代码 不包含的test目录
mvn   clean  清除编译后的文件
mvn   test  构建主程序的代码  构建test目录的代码
mvn   package 将项目进行打包
mvn   install  将项目打包放入本地仓库  提供给其它项目进行使用

通过Idea打开 cmd,然后执行Maven指令

| 打开 cmd,并定位到项目目录 |

在这里插入图片描述

| 执行maven指令
在这里插入图片描述

7.2 Maven面板

Idea中有Maven面板,其中可以快速执行Maven指令

maven面板
在这里插入图片描述

八 依赖管理

8.1 基本概念

当A jar包需要用到B jar包中的类时,我们就说A对B有依赖。例如:commons-fileupload-1.3.jar依赖于commons-io-2.0.1.jar。

配置的基本形式是使用dependency标签指定目标jar包的坐标。例如:

<dependencies>
	<dependency>
		<!—坐标 -->
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<version>4.10</version>
		<!-- 依赖的范围 -->
		<scope>test</scope>
	</dependency>
</dependencies>
8.2 直接依赖和间接依赖

如果A依赖B,B依赖C,那么A→B和B→C都是直接依赖,而A→C是间接依赖。

8.3 依赖的传递性

当存在间接依赖的情况时,主工程对间接依赖的jar可以访问吗?这要看间接依赖的jar包引入时的依赖范围——只有依赖范围为compile时可以访问。例如:

8.4 依赖的原则:解决jar包冲突

①路径最短者优先

②路径相同时先声明者优先

这里“声明”的先后顺序指的是dependency标签配置的先后顺序。

8.5 依赖的排除

有的时候为了确保程序正确可以将有可能重复的间接依赖排除。请看如下的例子:


<dependency>
	<groupId>org.javaboy.maven</groupId>
	<artifactId>Survey160225_4_Environment</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<!-- 依赖排除 -->
	<exclusions>
		<exclusion>
			<groupId>commons-logging</groupId>
			<artifactId>commons-logging</artifactId>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupId>commons-logging</groupId>
	<artifactId>commons-logging</artifactId>
	<version>1.1.2</version>
</dependency>

八 maven中对jar的版本进行统一管理

8.1 原因
在实例化开发中 需要使用一些框架 而这些框架对用很多版本,使用不同的版本,可能出现jar的冲突,造成开发速度变慢,所以一般在使用框架的使用框架的时候,都会对jar的版本进行统一管理,有利对jar的维护,也避免一些错误的产生
8.2 步骤

step01 声明版本

在这里插入图片描述

step02 通过el表达式获取
在这里插入图片描述

注意点: 在子父工程中 可以通过在父工程中锁定版本号 那么子工程可以省略版本号了

父工程
在这里插入图片描述

子工程

在这里插入图片描述

十 maven项目中聚合与拆分

注意点:子模块需要相互调用 必须先安装在本地仓库中 在添加依赖才能进行调用

十一 使用内置tomcat

step01
在这里插入图片描述

step03 在当前项目下进行配置

<plugin>
  <groupId>org.apache.tomcat.maven</groupId>
  <artifactId>tomcat7-maven-plugin</artifactId>
  <version>2.2</version>
  <configuration>
    <url>http://localhost/manager/text</url>
    <server>tomcat7</server>
    <username>tomcat</username>
    <password>tomcat</password>
    <port>80</port> ==> 修改端口号
    <path>/</path>  ==>修改访问的路径
  </configuration>
</plugin>

十二 依赖下载失败

A.pom.xml中 选中文件单击 选中maven==>reimprot
B.删除本地仓库的下载失败临时的文件 文件名为.lastUpdated
C.切换远程仓库的镜像 阿里与华为云
D.反复修改配置文件中的镜像 进行切换 更新

用 必须先安装在本地仓库中 在添加依赖才能进行调用

十一 使用内置tomcat

step01

[外链图片转存中…(img-iKMK6TJn-1655774839836)]

step03 在当前项目下进行配置

<plugin>
  <groupId>org.apache.tomcat.maven</groupId>
  <artifactId>tomcat7-maven-plugin</artifactId>
  <version>2.2</version>
  <configuration>
    <url>http://localhost/manager/text</url>
    <server>tomcat7</server>
    <username>tomcat</username>
    <password>tomcat</password>
    <port>80</port> ==> 修改端口号
    <path>/</path>  ==>修改访问的路径
  </configuration>
</plugin>

十二 依赖下载失败

A.pom.xml中 选中文件单击 选中maven==>reimprot
B.删除本地仓库的下载失败临时的文件 文件名为.lastUpdated
C.切换远程仓库的镜像 阿里与华为云
D.反复修改配置文件中的镜像 进行切换 更新
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值