• Maven 安装和配置
    • Maven 安装
    • Maven 配置
    • 资料

    Maven 安装和配置

    Maven 安装

    • Maven 安装

      • 官网:http://maven.apache.org/
      • 官网下载:http://maven.apache.org/download.cgi
      • 历史版本下载:https://archive.apache.org/dist/maven/binaries/
      • 此时(20160208) Maven 最新版本为:3.3.9
      • Maven 3.3 的 JDK 最低要求是 JDK 7
      • 我个人习惯 /opt 目录下创建一个目录 setups 用来存放各种软件安装包;在 /usr 目录下创建一个 program 用来存放各种解压后的软件包,下面的讲解也都是基于此习惯
      • 我个人已经使用了第三方源:EPEL、RepoForge,如果你出现 yum install XXXXX 安装不成功的话,很有可能就是你没有相关源,请查看我对源设置的文章
      • 下载压缩包:wget http://mirrors.cnnic.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
      • 解压:tar zxvf apache-maven-3.3.9-bin.tar.gz
      • 修改目录名,默认的太长了:mv apache-maven-3.3.9/ maven3.3.9/
      • 移到我个人习惯的安装目录下:mv maven3.3.9/ /usr/program
      • 环境变量设置:vim /etc/profile
      • 在文件最尾巴添加下面内容:

        1. # Maven
        2. MAVEN_HOME=/usr/program/maven3.3.9
        3. PATH=$PATH:$MAVEN_HOME/bin
        4. MAVEN_OPTS="-Xms256m -Xmx356m"
        5. export MAVEN_HOME
        6. export PATH
        7. export MAVEN_OPTS
      • 刷新配置文件:source /etc/profile

      • 测试是否安装成功:mvn -version

    Maven 配置

    • 配置项目连接上私服
    • 全局方式配置:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <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">
    3. <!--本地仓库位置-->
    4. <localRepository>D:/maven/my_local_repository</localRepository>
    5. <pluginGroups>
    6. </pluginGroups>
    7. <proxies>
    8. </proxies>
    9. <!--设置 Nexus 认证信息-->
    10. <servers>
    11. <server>
    12. <id>nexus-releases</id>
    13. <username>admin</username>
    14. <password>admin123</password>
    15. </server>
    16. <server>
    17. <id>nexus-snapshots</id>
    18. <username>admin</username>
    19. <password>admin123</password>
    20. </server>
    21. </servers>
    22. <!--设置 Nexus 镜像,后面只要本地没对应的以来,则到 Nexus 去找-->
    23. <mirrors>
    24. <mirror>
    25. <id>nexus-releases</id>
    26. <mirrorOf>*</mirrorOf>
    27. <url>http://localhost:8081/nexus/content/groups/public</url>
    28. </mirror>
    29. <mirror>
    30. <id>nexus-snapshots</id>
    31. <mirrorOf>*</mirrorOf>
    32. <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
    33. </mirror>
    34. </mirrors>
    35. <profiles>
    36. <profile>
    37. <id>nexus</id>
    38. <repositories>
    39. <repository>
    40. <id>nexus-releases</id>
    41. <url>http://nexus-releases</url>
    42. <releases>
    43. <enabled>true</enabled>
    44. </releases>
    45. <snapshots>
    46. <enabled>true</enabled>
    47. </snapshots>
    48. </repository>
    49. <repository>
    50. <id>nexus-snapshots</id>
    51. <url>http://nexus-snapshots</url>
    52. <releases>
    53. <enabled>true</enabled>
    54. </releases>
    55. <snapshots>
    56. <enabled>true</enabled>
    57. </snapshots>
    58. </repository>
    59. </repositories>
    60. <pluginRepositories>
    61. <pluginRepository>
    62. <id>nexus-releases</id>
    63. <url>http://nexus-releases</url>
    64. <releases>
    65. <enabled>true</enabled>
    66. </releases>
    67. <snapshots>
    68. <enabled>true</enabled>
    69. </snapshots>
    70. </pluginRepository>
    71. <pluginRepository>
    72. <id>nexus-snapshots</id>
    73. <url>http://nexus-snapshots</url>
    74. <releases>
    75. <enabled>true</enabled>
    76. </releases>
    77. <snapshots>
    78. <enabled>true</enabled>
    79. </snapshots>
    80. </pluginRepository>
    81. </pluginRepositories>
    82. </profile>
    83. </profiles>
    84. <activeProfiles>
    85. <activeProfile>nexus</activeProfile>
    86. </activeProfiles>
    87. </settings>
    • 项目级别:

    资料

    • http://maven.apache.org/install.html
    • http://www.tutorialspoint.com/maven/index.htm
    • http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
    • http://maven.apache.org/guides/getting-started/index.html
    • http://maven.apache.org/general.html
    • http://stackoverflow.com/questions/6950346/infrastructure-with-maven-jenkins-nexus
    • http://blog.csdn.net/sxyx2008/article/details/7975129
    • http://blog.csdn.net/xuke6677/article/details/8482472