RHEL5 JDK6 安装配置及示例 (Red Hat Enterprise Linux 5)

时间:2022-08-08 09:18:14

JDK1.6 下载: http://java.sun.com/javase/downloads/widget/jdk6.jsp

 

我下载的是jdk-6u18-linux-i586-rpm.bin

 

首先卸载rhel5自带的jdk:(命令)yum remove java

 

然后cd到已下载的jdk文件夹 直接运行 ./jdk-6u18-linux-i586-rpm.bin

 

安装好后,接下来就是配置环境变量了,我的jdk默认安装目录:/usr/java/jdk1.6.0_18

 

 [root@localhost ~]# vi /etc/profile

在文件最后添加


#jdk1.6 env
export JAVA_HOME=/usr/java/jdk1.6.0_18/
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/td.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH

保存退出,重启系统

接下来就可以使用安装的jdk了

 

下面我们做一个测试,使用vi编辑器,创建TestSystem.java(命令 vi TestSystem.java),输入:

 

public class TestSystem {
        public static void main(String[] args) {
                Properties props = System.getProperties();
                Set<String> propNames = props.stringPropertyNames();
                for(String name : propNames) {
                        System.out.println(name + "="  + props.getProperty(name));
                }
        }
}

wq保存并退出

运行结果:

[root@localhost java_app]# javac TestSystem.java
[root@localhost java_app]# java TestSystem
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=/usr/java/jdk1.6.0_18/jre/lib/i386
java.vm.version=16.0-b13
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=:
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io
user.country=US
sun.java.launcher=SUN_STANDARD
sun.os.patch.level=unknown
java.vm.specification.name=Java Virtual Machine Specification
user.dir=/usr/local/java_app
java.runtime.version=1.6.0_18-b07
java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment
java.endorsed.dirs=/usr/java/jdk1.6.0_18/jre/lib/endorsed
os.arch=i386
java.io.tmpdir=/tmp
line.separator=

java.vm.specification.vendor=Sun Microsystems Inc.
os.name=Linux
sun.jnu.encoding=UTF-8
java.library.path=/usr/java/jdk1.6.0_18/jre/lib/i386/client:/usr/java/jdk1.6.0_18/jre/lib/i386:/usr/java/jdk1.6.0_18/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib
java.specification.name=Java Platform API Specification
java.class.version=50.0
sun.management.compiler=HotSpot Client Compiler
os.version=2.6.18-53.el5xen
user.home=/root
user.timezone=
java.awt.printerjob=sun.print.PSPrinterJob
file.encoding=UTF-8
java.specification.version=1.6
user.name=root
java.class.path=.:/usr/java/jdk1.6.0_18//lib/td.jar:/usr/java/jdk1.6.0_18//lib/tools.jar
java.vm.specification.version=1.0
sun.arch.data.model=32
java.home=/usr/java/jdk1.6.0_18/jre
java.specification.vendor=Sun Microsystems Inc.
user.language=en
java.vm.info=mixed mode, sharing
java.version=1.6.0_18
java.ext.dirs=/usr/java/jdk1.6.0_18/jre/lib/ext:/usr/java/packages/lib/ext
sun.boot.class.path=/usr/java/jdk1.6.0_18/jre/lib/resources.jar:/usr/java/jdk1.6.0_18/jre/lib/rt.jar:/usr/java/jdk1.6.0_18/jre/lib/sunrsasign.jar:/usr/java/jdk1.6.0_18/jre/lib/jsse.jar:/usr/java/jdk1.6.0_18/jre/lib/jce.jar:/usr/java/jdk1.6.0_18/jre/lib/charsets.jar:/usr/java/jdk1.6.0_18/jre/classes
java.vendor=Sun Microsystems Inc.
file.separator=/
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi
sun.cpu.endian=little
sun.io.unicode.encoding=UnicodeLittle
sun.cpu.isalist=