环境描述:Ubuntu Server 12.04 / java-6-sun-1.6.0.06 / apache-maven-3.0.4
1、安装sun-jdk
因为sun-jdk被Oracle收购了,所以Ubuntu支持开源,当前已经没有oracle java jdk新版本的更新源了,所以要安装sun-jdk,只能安装老版本,并且必须要更新Ubuntu的下载源,如下:
需要安装
>> apt-get install python-software-properties
将sun-6-jre的下载源更新到sources.list中
>> add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ hardy multiverse"
然后就可以通过命令行直接安装了,安装之前需要更新列表apt-get update
>> apt-get install sun-java6-jdk
通常情况下,Ubuntu server会默认选择安装openjdk,所以这里大家要更改jdk的优先级以及指令链接如下:
>> update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-6-sun-1.6.0.06/bin/java 300
>> update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-6-sun-1.6.0.06/bin/javac 300
接着修改默认的JDK
>> sudo update-alternatives --config java,如下选择默认使用的jdk
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
* 2 /usr/lib/jvm/java-6-sun-1.6.0.06/bin/java 300 manual mode
3 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode
Press enter to keep the current choice[*], or type selection number: 这里选择 2 即可
至此,sun-jdk被默认安装在了/usr/lib/jvm/java-6-sun-1.6.0.06
2、安装maven2
到http://maven.apache.org/去下载maven的最新版本,当前是apache-maven-3.0.4,包选择apache-maven-3.0.4-bin.tar.gz
将apache-maven-3.0.4-bin.tar.gz上传到/usr/share目录下,通过如下命令解压
>> tar -zxvf apache-maven-3.0.4-bin.tar.gz 至 /usr/share/apache-maven-3.0.4
至此maven的安装完成
3、配置Java和maven的环境变量
>> vi /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$JAVA_HOME/bin:$MAVEN_HOME/bin"
JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.06
CLASSPATH=.:$JAVA_HOME/lib
MAVEN_HOME=/usr/share/apache-maven-3.0.4
export JAVA_HOME
export MAVEN_HOME
export CLASSPATH
export PATH
此处的PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin,可以单独作为一行单列也可以。
保存之后,重新其中环境变量使之生效
>> . /etc/environment
4、检测Java和maven配置是否成功
>> java -version
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) 64-Bit Server VM (build 10.0-b22, mixed mode)
>> mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 08:44:56+0000)
Maven home: /usr/share/apache-maven-3.0.4
Java version: 1.6.0_06, vendor: Sun Microsystems Inc.
Java home: /usr/lib/jvm/java-6-sun-1.6.0.06/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.2.0-24-virtual", arch: "amd64", family: "unix"
到此表示Java和Maven的环境配置成功!
声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。