maven

0 常用网址
0.1 maven官网:https://maven.apache.org/
0.2 maven中央仓库jar坐标检索网站:https://mvnrepository.com/

1 maven版本与java版本配合问题
https://maven.apache.org/docs/history.html

2 maven下载
2.1 进入网址 https://maven.apache.org/
2.2 点击 Download 选项

2.3 点击 archives 选项

2.4 点击想要下载的版本

2.5 点击 binaries/ 选项(这里以3.8.6版本为例)

2.6 根据电脑系统选择下载

3 maven安装
-将下载好的压缩包解压即可-

4 maven环境变量配置






5 检查环境变量配置是否成功
mvn -v

6 修改settings.xml文件
私服配置可参考:https://www.cnblogs.com/gaoguanghui/p/18383784
6.1

  <!-- 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:\work\apache-maven-3.8.6\mavenRepository</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>
  -->

6.2

    <!-- 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>
    -->
    <!--添加aliyun的maven仓库作为远程仓库-->
    <mirror>
      <!--id标签内容随便写一个-->
      <id>aliyun</id>
      <!--central 表示本地将这个仓库定义为中央仓库的镜像仓库使用,此时当本地需要下载jar时会在本地设置的中央仓库的镜像仓库也就是此仓库去下载jar。central固定不可修改-->
      <mirrorOf>central</mirrorOf>
      <!--name标签内容随便写一个-->
      <name>Nexus aliyun</name>
      <!-- aliyun的maven仓库地址 以后所有要指向中心仓库的请求,都会指向aliyun的maven仓库-->
      <url>http://maven.aliyun.com/nexus/content/groups/public</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.

6.3

    <!-- 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>
    -->
    <!--配置自己的jdk-->
    <profile>
      <id>myjdk</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>

    <!--
     | 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:

6.4

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
  <!--让自己配置的jdk生效-->
  <activeProfiles>
	<activeProfile>myjdk</activeProfile>
  </activeProfiles>

6.5 修改后的maven的settings.xml文件
https://files.cnblogs.com/files/blogs/735709/settings(maven%E5%8F%82%E8%80%83).xml?t=1688828643&download=true
6.6 idea绑定maven

7 maven项目结构

8 创建maven项目

修改目录结构和文件内容,依照下图

mavenapptest项目下载:
https://files.cnblogs.com/files/blogs/735709/mavenapptest.zip?t=1724825632&download=true

9 创建多模块maven项目

10 maven常用命令

11 maven插件

注. 参考https://blog.csdn.net/weixin_41846320/article/details/81671535

posted @   略乏旅人  阅读(67)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示