歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> 學習Linux

CentOS自動安裝Maven

CentOS自動安裝Maven


熱度2 評論 235 www.BkJia.Com  網友分享於:  2017-02-28 06:02:55     浏覽數18127次

CentOS自動安裝Maven


1. 自動下載Maven

2. 設置環境變量

3. 配置mirror

安裝:下載maven.rar按照 readme 執行即可

mirror配置:

[html]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. <mirror>
  2. <id>alimaven</id>
  3. <name>aliyunmaven</name>
  4. <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  5. <mirrorOf>central</mirrorOf>
  6. </mirror>
  7. <mirror>
  8. <id>central</id>
  9. <name>MavenRepositorySwitchboard</name>
  10. <url>http://repo1.maven.org/maven2/</url>
  11. <mirrorOf>central</mirrorOf>
  12. </mirror>
  13. <mirror>
  14. <id>repo2</id>
  15. <mirrorOf>central</mirrorOf>
  16. <name>HumanReadableNameforthisMirror.</name>
  17. <url>http://repo2.maven.org/maven2/</url>
  18. </mirror>
  19. <mirror>
  20. <id>ibiblio</id>
  21. <mirrorOf>central</mirrorOf>
  22. <name>HumanReadableNameforthisMirror.</name>
  23. <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
  24. </mirror>
  25. <mirror>
  26. <id>jboss-public-repository-group</id>
  27. <mirrorOf>central</mirrorOf>
  28. <name>JBossPublicRepositoryGroup</name>
  29. <url>http://repository.jboss.org/nexus/content/groups/public</url>
  30. </mirror>
  31. <mirror>
  32. <id>maven.net.cn</id>
  33. <name>oneofthecentralmirrorsinchina</name>
  34. <url>http://maven.net.cn/content/groups/public/</url>
  35. <mirrorOf>central</mirrorOf>
  36. </mirror>

############################# 結束符 ##########################

貼上shell 文件:

[html]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. #!/bin/sh
  2. #關閉進程
  3. killpids(){
  4. pids=($(ps-ef|grep$1|awk'{print$2}'))
  5. forpidin${pids[@]};do
  6. echo"關閉進程:pid${pid}"
  7. kill-9${pid}
  8. done
  9. }
  10. killpidsmaven
  11. #刪除舊版maven
  12. echo"刪除舊版maven"
  13. rm-rf/usr/local/apache-maven-*
  14. #installmaven
  15. srcPath=$(find/usr/maven-maxdepth1-typef|grep'.*maven.*.tar.gz$')
  16. if[[$srcPath=~"maven"]]
  17. then
  18. echo"安裝包:$srcPath"
  19. rpm-ivh$srcPath
  20. else
  21. #下載maven
  22. yum-yinstallwget
  23. echo-e"DownloadMaven"
  24. wgethttp://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz-P/usr/maven/
  25. srcPath=$(find/usr/maven-maxdepth1-typef|grep'.*maven.*.tar.gz$')
  26. fi
  27. #解壓
  28. echo"解壓..."
  29. tar-xf$srcPath-C/usr/local
  30. path=$(find/usr/local-maxdepth1-typed|grep'apache-maven-.*')
  31. dir_name=${path##*/}
  32. echo$path
  33. echo$dir_name
  34. #賦予權限
  35. chmod-R755$path
  36. #設置環境變量
  37. sed-i'/M2_HOME/d'/etc/profile
  38. echo"設置環境變量"
  39. echo"exportM2_HOME=$path">>/etc/profile
  40. echo'exportPATH=$PATH:$M2_HOME/bin'>>/etc/profile
  41. source/etc/profile
  42. echo"建立軟鏈接$path->apache-maven"
  43. ln-s$pathapache-maven
  44. echo"配置mirrors"
  45. IFSBAK=$IFS#備份原來的值
  46. IFS=#
  47. mirror="
  48. #<mirror>
  49. #<id>alimaven</id>
  50. #<name>aliyunmaven</name>
  51. #<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  52. #<mirrorOf>central</mirrorOf>
  53. #</mirror>
  54. #<mirror>
  55. #<id>central</id>
  56. #<name>MavenRepositorySwitchboard</name>
  57. #<url>http://repo1.maven.org/maven2/</url>
  58. #<mirrorOf>central</mirrorOf>
  59. #</mirror>
  60. #<mirror>
  61. #<id>repo2</id>
  62. #<mirrorOf>central</mirrorOf>
  63. #<name>HumanReadableNameforthisMirror.</name>
  64. #<url>http://repo2.maven.org/maven2/</url>
  65. #</mirror>
  66. #<mirror>
  67. #<id>ibiblio</id>
  68. #<mirrorOf>central</mirrorOf>
  69. #<name>HumanReadableNameforthisMirror.</name>
  70. #<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
  71. #</mirror>
  72. #<mirror>
  73. #<id>jboss-public-repository-group</id>
  74. #<mirrorOf>central</mirrorOf>
  75. #<name>JBossPublicRepositoryGroup</name>
  76. #<url>http://repository.jboss.org/nexus/content/groups/public</url>
  77. #</mirror>
  78. #<mirror>
  79. #<id>maven.net.cn</id>
  80. #<name>oneofthecentralmirrorsinchina</name>
  81. #<url>http://maven.net.cn/content/groups/public/</url>
  82. #<mirrorOf>central</mirrorOf>
  83. #</mirror>
  84. #'
  85. "
  86. #循環寫入文件
  87. forlinein$mirror;
  88. do
  89. sed-i"/<\/mirrors>/i\$line"$path/conf/settings.xml
  90. done
  91. IFS=$IFSBAK#還原
  92. echo"mvn-v"
  93. mvn-v
  94. echo""

http://www.bkjia.com/Linuxjc/1195996.htmlwww.bkjia.comtrue

Copyright © Linux教程網 All Rights Reserved