zoukankan      html  css  js  c++  java
  • Maven知识点简要

     
    1、依赖管理
    <dependencies>
    <dependency>
      <groupId>net.sf.json-lib</groupId>
      <artifactId>json-lib</artifactId>
      <version>2.2.2</version>
      <type>jar</type>
      <scope>compile</scope>   scope  compile:默认   test:测试包下可以,打包不加入,比如:junit    provided:编译和测试的依赖,打包不加入,比如:servlet-api
    </dependency>
    </dependencies>
     
    dependencies与dependencyManagement区别

    dependencies即使在子项目中不写该依赖项,那么子项目仍然会从父项目中继承该依赖项(全部继承)

    dependencyManagement里只是声明依赖,并不实现引入,因此子项目需要显示的声明需要用的依赖。

     
    2、阿里镜像,修改settings
    <mirrors>
      <mirror>
        <id>maven.net.cn</id>
        <name>one of the central mirrors in china</name>
        <url>http://maven.net.cn/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
      </mirror>

      <mirror>  

          <id>alimaven</id>  

          <name>aliyun maven</name>  

          <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  

         <mirrorOf>central</mirrorOf>          

      </mirror>

      <mirror>

        <id>ui</id>

        <mirrorOf>central</mirrorOf>

        <name>Human Readable Name for this Mirror.</name>

        <url>http://uk.maven.org/maven2/</url>

      </mirror>

      <mirror>

                <id>osc</id>

                <mirrorOf>central</mirrorOf>

                <url>http://maven.oschina.net/content/groups/public/</url>

            </mirror>

            <mirror>

                <id>osc_thirdparty</id>

                <mirrorOf>thirdparty</mirrorOf>

                <url>http://maven.oschina.net/content/repositories/thirdparty/</url>

            </mirror>

    </mirrors>

     

     
    3、聚合与继承
    聚合
    一般聚合项目用<packaging>pom</packaging>
    聚合项目与子项目平行目录结构的配置
    <modules>
    <module>../subModule1</module>
    <module>../subModule2</module>
    </modules>
     
    继承
    <perent>
    <groupId></groupId>
    <artifactId></artifactId>
    <version></version>
    <relativePath></relativePath>
    </parent>
    父模块dependencyManagement中定义的依赖:不会为父模块和子模块实际依赖,必须在子模块定义实际定义才行,而dependencies为导致父模块和所有子模块的依赖不必要的资源;pluginManagement和plugins有相同的道理
     
     
    4、maven将本地jar包添加到本地仓库

    maven在pom文件里引用本地jar

    方法1:

        <dependency> 
            <groupId>org.wltea</groupId> 
            <artifactId>IKAnalyzer</artifactId> 
            <version>2012_u6</version> 
            <scope>system</scope> 
            <systemPath>E:/repositories/IKAnalyzer2012_u6.jar</systemPath> 
        </dependency>

     
    方法2:
    到maven/bin 路径下,启动cmd窗口,执行 命令: 
     
     mvn install:install-file -Dfile=rest-2.6.3.jar -DgroupId=com.cloopen -DartifactId=rest -Dversion=2.6.3 -Dpackaging=jar 

    mvn install:install-file -Dfile=jar包的位置 -DgroupId=一般是公司名倒序 -DartifactId=唯一型ID -Dversion=版本号 -Dpackaging=jar  
     
    IDEA命令拉取jar包源码:

    执行mvn命令:
    下载所有pom依赖包的source:mvn dependency:resolve -Dclassifier=sources
    下载指定依赖包的source:mvn dependency:sources -DincludeArtifactIds=guava
    其中guava为ArtifactId

  • 相关阅读:
    springboot 2.4.5 redis 配置类+缓存
    华为ensp模拟器 提示40 错误问题
    Nodejs
    Python PermissionError:[Errno 13]权限被拒绝 [winerr 5]
    Window10的linux docker 安装(wsl版本)
    window10的 Linux 子系统ssh配置
    vue3.0中provide和inject实现响应式传值
    正确开启vue3.0调试工具vue-devtools
    vue动态设置组件样式
    element-ui菜单导航的三种递归写法(三)
  • 原文地址:https://www.cnblogs.com/hero123/p/9244864.html
Copyright © 2011-2022 走看看