最新地址请查看博客:http://blog.360chwl.net/detail/8a2390184c987b3e014c9cab989c0004.html
准备:
+ Redhat AS4 Update5, JDK1.5
+ http://www.sun.com 分别可以下载 jdk
安装 java 环境:
其实AS4 update5中已经安装了jdk1.5了,所以这里会提示系统已经安装,如果是其他版本的Linux可以参照以下步骤:
+ 新建终端, 进入 jdk 存放目录, 执行:
./jdk-1_5_0-linux-i586-rpm.bin
出现 jdk 的安装 licence, 把它看完后, 会问你是否同意安装, 键入 yes 回车安装.
+ 执行完后在当前目录中会存在 jdk-1_5_0-linux-i586-rpm 文件, 你可以用 ls 命令查看. 然后执行
rpm -ivh jdk-1_5_0-linux-i586-rpm
这样, jdk 默认安装到 /usr 目录中去了, 我这里是: /usr/java/jdk1.5.0
vi /etc/profile
在最后添加以下内容, jdk 路径请改为你相应的路径
export JAVA_HOME = /usr/java/jdk1.5.0
export CLASSPATH = $JAVA_HOME/lib:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH = $PATH:$JAVA_HOME/bin
保存退出
如果键入java后显示
Usage: gij [OPTION] ... CLASS [ARGS] ...
to invoke CLASS.main, or
gij -jar [OPTION] ... JARFILE [ARGS] ...
to execute a jar file
Try `gij --help' for more information.
说明系统默认指向的不是刚才安装的jdk版本,查看下:
[root@dell tv2.0]# which java/usr/bin/java
[root@dell software]# ls /usr/bin/java -l
lrwxrwxrwx 1 root root 22 08-5 21:23 /usr/bin/java -> /etc/alternatives/java
[root@dell software]# ll /etc/alternatives/java
lrwxrwxrwx 1 root root 35 08-5 21:48 /etc/alternatives/java -> /usr/lib/jvm/jre-1.4.2-gcj/bin/ java
使用alternatives工具修改:
先安装新的版本
[root@dell software]# alternatives --install /usr/bin/java java /usr/java/jdk1.5.0/bin/java 300
修改配置:
[root@dell02 ~]# java -version
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Server VM (build 1.5.0-b64, mixed mode)
[root@dell02 ~]# alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
* 1 /usr/lib/jvm/jre-1.4.2-gcj/bin/java
+ 2 /usr/java/jdk1.5.0/bin/java
Enter to keep the current selection[+], or type selection number:
选择2,
验证:
[root@dell02 ~]# java
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is server,
because you are running on a server-class machine.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
OK.