• Maven的详解


    ``        在java中Maven就是一个包管理工具,在没有包管理工具时,我们要做一个java项目,需要第三方依赖包,将别人打包好的Jar包下载到本地,然后手动指定给项目.操作比较麻烦,比如版本控制,有的甚至还有其他包的依赖,属实是繁琐,技术是不断地迭代的,所以就出现了Maven,用了Maven之后,需要什么包,直接在pom.xml中添加xml代码,指定包名 版本等.很方便我们开发人员进行项目的部署以及开发.

    1. <dependency>
    2. <groupId>mysqlgroupId>
    3. <artifactId>mysql-connector-javaartifactId>
    4. <version>8.0.16version>//版本
    5. dependency>

    Maven默认为从中央 仓库下载Jar包的,中央仓库在国外,所以速度很慢.

    我们为什么要学习Maven?

    • Jar包难以寻找
    • Jar包的依赖难以解决
    • Jar包不容易管理
    • 项目编译

     2.Maven 简介
    Maven 是 Apache 软件基金会的一个开源项目,是一个优秀的项目构建工具,它
    用来帮助开发者管理项目中的 jar,以及 jar 之间的依赖关系、完成项目的编译、
    测试、打包和发布等工作。

    3.如何找到Jar包的位置?

    在我们生活中,高得地图为什么能够准确的找到我们想要找到的位置呢?还有比较准确的位置导航,是不是因为每个位置都有一个属于自己的坐标,我们在输入所要查询的地点其实是默认给了它一个位置坐标,Maven中也是这样的原理,maven 给每个 jar 定义了唯一的标志,这个在 maven 中叫做项目的坐标,通过这个坐标可以找到你需要 用到的任何版本的 jar 包。

    1. "1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    5. <modelVersion>4.0.0modelVersion>
    6. <groupId>com.examplegroupId>
    7. <artifactId>mavenDemoartifactId>
    8. <version>1.0.0version>
    9. <name>mavenDemoname>
    10. <packaging>warpackaging>
    11. <properties>
    12. <maven.compiler.target>1.8maven.compiler.target>
    13. <maven.compiler.source>1.8maven.compiler.source>
    14. <junit.version>5.6.2junit.version>
    15. properties>
    16. <dependencies>
    17. <dependency>
    18. <groupId>mysqlgroupId>
    19. <artifactId>mysql-connector-javaartifactId>
    20. <version>8.0.16version>
    21. <type>jartype>
    22. dependency>
    23. <dependency>
    24. <groupId>commons-fileuploadgroupId>
    25. <artifactId>commons-fileuploadartifactId>
    26. <version>1.3.1version>
    27. <type>jartype>
    28. <scope>compilescope>
    29. dependency>
    30. <dependency>
    31. <groupId>javax.servletgroupId>
    32. <artifactId>javax.servlet-apiartifactId>
    33. <version>3.1.0version>
    34. <scope>providedscope>
    35. dependency>
    36. <dependency>
    37. <groupId>com.examplegroupId>
    38. <artifactId>myUtilartifactId>
    39. <version>1.0-SNAPSHOTversion>
    40. dependency>
    41. dependencies>
    42. <build>
    43. <plugins>
    44. <plugin>
    45. <groupId>org.apache.maven.pluginsgroupId>
    46. <artifactId>maven-war-pluginartifactId>
    47. <version>3.3.0version>
    48. plugin>
    49. plugins>
    50. build>
    51. project>

     基本流程:

    1.安装JDk,较好的网络环境

    2.下载Maven服务器

    3.对Maven环境进行配置  

    4.在电脑中创建一个存储从镜像仓库下载Jar包的文件夹,一般我们称为”仓库(repository),在 maven 的服务器解压的文件中找到 conf 文件夹下的settings.xml 文件进行修改,如下图所示:


    配置阿里云 maven 镜像仓库,下载速度更快

    1. <mirror>
    2. <id>alimavenid>
    3. <name>aliyun mavenname>
    4. <url>http://maven.aliyun.com/nexus/content/groups/public/url>
    5. <mirrorOf>centralmirrorOf>
    6. mirror>

     5.从idea中设置Maven

     

     

     

     6.Pom.xml 配置

    maven 仓库官网(http://mvnrepository.com/)

    7.Maven命令

    1. compile 编译
    2. clean
    删除 target
    3. package 打包​
    4. install
    把项目 install 到本地仓库
    5. test
    运行测试代码

  • 相关阅读:
    【华为OD机试真题 python】 转骰子【2022 Q4 | 200分】
    [数据结构]实现双向链表
    C++ 运算符重载
    自适应对话式团队构建,提升语言模型代理的复杂任务解决能力
    PC电脑能不能当服务器用?
    第17章 其他数据库日志【4.日志与备份篇】【MySQL高级】
    vue3项目中使用富文本编辑器
    分文件编译
    电脑出现xinput1_3.dll的错误提示怎么办?有什么办法可以解决
    Word中插入或修改文字时后面的字消失了该怎么办
  • 原文地址:https://blog.csdn.net/dfdbb6b/article/details/127894082