ubuntu maven环境安装配置

转载地址:http://my.oschina.net/hongdengyan/blog/150472#OSC_h1_4

一、环境说明:

操作系统:Ubuntu 12.04.2 LTS

maven:apache-maven-3.1.0

安装maven前请先安装好jdk,jdk安装可参见:http://my.oschina.net/hongdengyan/blog/150342。

二、下载 maven

下载链接:http://maven.apache.org/download.cgi

选择最新版本的maven安装包,我安装时最新安装包是apache-maven-3.1.0-bin.tar.gz。

下载保存文件的路径是:~/下载/。

三、解压安装

yan@yan-Ubuntu:/$ cd ~/下载

yan@yan-Ubuntu:/$ cd ~/下载

apache-maven-3.1.0-bin.tar.gz

yan@yan-Ubuntu:~/下载$ tar -zxvf apache-maven-3.1.0-bin.tar.gz

yan@yan-Ubuntu:~/下载$ ls

apache-maven-3.1.0

yan@yan-Ubuntu:~/下载$ sudo mv apache-maven-3.1.0 /usr/local/

yan@yan-Ubuntu:~/下载$ ls /usr/local

apache-maven-3.1.0  bin  eclipse  etc  games  include  java  lib  man  sbin  share  src

四、设置环境变量

以root身份打开并编辑profile文件:

yan@yan-Ubuntu:/$ sudo gedit /etc/profile

在文件最后添加:

#set maven environment
M2_HOME=/usr/local/apache-maven-3.1.0

export MAVEN_OPTS="-Xms256m -Xmx512m"

export PATH=$M2_HOME/bin:$PATH

 

保存并关闭。

要使配置生效必须重启机器或者在命令行输入:

yan@yan-Ubuntu:/$ . /etc/profile

yan@yan-Ubuntu:/$ mvn -version

Apache Maven 3.1.0 (893ca28a1da9d5f51ac03827af98bb730128f9f2; 2013-06-28 10:15:32+0800)
Maven home: /usr/local/apache-maven-3.1.0
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /usr/local/java/jdk1.7.0_25/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.5.0-23-generic", arch: "i386", family: "unix"

五、配置用户范围setting.xml

yan@yan-Ubuntu:/$ sudo cp /usr/local/apache-maven-3.1.0/conf/settings.xml ~/.m2

yan@yan-Ubuntu:/$ sudo gedit ~/.m2/settings.xml

在文件中找到

<!-- 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
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->

 <localRepository>/home/yan/code/repository/maven</localRepository>

 其中:/home/yan/code/repository/maven是你maven本地仓库的路径。

 

posted @ 2014-04-18 19:23  demoblog  阅读(25147)  评论(0编辑  收藏  举报