Automatic Installation of Maven in CentOS

Source: Internet
Author: User
Tags aliyun

Automatic Installation of Maven in CentOS

1. automatically download Maven

2. Set Environment Variables

3. Configure mirror

Install: Download maven.rar and execute it according to readme.

Mirror Configuration:

[Html] view plaincopy
  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>

############################# Terminator ######### #################

Paste the shell file:

[Html] view plaincopy
  1. #! /Bin/sh
  2. # Closing a process
  3. Killpids (){
  4. Pids = ($ (ps-ef | grep $1 | awk '{print $2 }'))
  5. Forpidin $ {pids [@]}; do
  6. Echo "Closing Process: pid $ {pid }"
  7. Kill-9 $ {pid}
  8. Done
  9. }
  10. Killpidsmaven
  11. # Deleting old maven versions
  12. Echo "delete old 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 "installation package: $ srcPath"
  19. Rpm-ivh $ srcPath
  20. Else
  21. # Download maven
  22. Yum-yinstallwget
  23. Echo-e "DownloadMaven"
  24. Wgethttp: // response/
  25. SrcPath = $ (find/usr/maven-maxdepth1-typef | grep '. * maven. * .tar.gz $ ')
  26. Fi
  27. # Decompress
  28. Echo "decompress ..."
  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. # Granting permissions
  35. Chmod-R755 $ path
  36. # Setting Environment Variables
  37. Sed-I '/M2_HOME/D'/etc/profile
  38. Echo "set environment variables"
  39. Echo "exportM2_HOME = $ path">/etc/profile
  40. Echo 'exportpath = $ PATH: $ M2_HOME/bin'>/etc/profile
  41. Source/etc/profile
  42. Echo "create soft link $ path-> apache-maven"
  43. Ln-s $ pathapache-maven
  44. Echo "Configuring mirrors"
  45. Ifsbsk = $ IFS # back up the original value
  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. # Circular file writing
  87. Forlinein $ mirror;
  88. Do
  89. Sed-I "/<\/mirrors>/I \ $ line" $ path/conf/settings. xml
  90. Done
  91. IFS = $ ifsbsk # restore
  92. Echo "mvn-v"
  93. Mvn-v
  94. Echo ""

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.