How to setup java development environment in the ubuntu(11.10)?

here are some steps:
  1. Choose a version of java and download it from the Oracle
    http://www.oracle.com/technetwork/java/javase/downloads/index.html
    I choose the jdk_1.7.0_03 here, and download it into ~/Downloads/
  2. Extract and install it.
    点击(此处)折叠或打开
    1. sudo tar zxvf ~/Downloads/jdk-7u3-linux-i586.tar.gz -C /usr/lib/jvm
    2. #Note please:
      #you can change the name of jdk,
      #BUT CAN'T create a symbolic link to it otherwise the you will get error message like below:
    3. ray@ray-laptop:~$ ls -l /usr/lib/jvm/
      total 4
      lrwxrwxrwx 1 ray ray   12 2012-04-21 15:57 java_7_sun -> jdk1.7.0_03/
      drwxr-xr-x 8 ray ray 4096 2012-01-21 02:37 jdk1.7.0_03
    4. ray@ray-laptop:~$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-7-sun/bin/java 300
      update-alternatives: error: alternative path /usr/lib/jvm/java-7-sun/bin/java doesn't exist.
    5. ray@ray-laptop:~$ ls -l /usr/lib/jvm/java_7_sun/bin/java
      -rwxr-xr-x 1 ray ray 5654 2012-01-21 02:27 /usr/lib/jvm/java_7_sun/bin/java

  3. Modify your Environment
    点击(此处)折叠或打开
    1. vim ~/.bashrc
    2. export JAVA_HOME=/usr/lib/jvm/jdk_1.7.0_03
    3. export JRE_HOME=${JAVA_HOME}/jre
    4. export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
    5. export PATH=${JAVA_HOME}/bin:$PATH
    6. #and then save it.
  4. Config the default java in your system:

    点击(此处)折叠或打开

    1. sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk_1.7.0_03/bin/java 300
    2. sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk_1.7.0_03/bin/javac 300
    3. sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk_1.7.0_03/bin/jar 300
    4. df
    5. sudo update-alternatives --config java 
    6. #and then follow the promotion and take your choice.
      #Here is my output of this command:
      "There is only one alternative in link group java: /usr/lib/jvm/jdk_1.7.0_03/bin/java
      Nothing to configure."

  5. Check your java now: 
  6. 点击(此处)折叠或打开

    1. ray@ray-laptop:~$ java -version
    2. java version "1.7.0_03"
    3. Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
    4. Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode)


Reference:


09-28 03:34