今天想把VPS的JDK重装一下,因为之前装的是JRE,貌似jetty跟JRE有点不兼容,老是打错误日志,提示java.err.nojdk

http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html上找到下载链接,直接wget,然后就报错了

[root@vps java]# wget http://download.oracle.com/otn/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin
--2014-02-18 21:47:58--  http://download.oracle.com/otn/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin
正在解析主机 download.oracle.com... 65.122.127.49, 65.122.127.43
Connecting to download.oracle.com|65.122.127.49|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Moved Temporarily
位置:https://edelivery.oracle.com/akam/otn/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin [跟随至新的 URL]
--2014-02-18 21:47:59--  https://edelivery.oracle.com/akam/otn/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin
正在解析主机 edelivery.oracle.com... 23.214.22.140
Connecting to edelivery.oracle.com|23.214.22.140|:443... 已连接。
ERROR: certificate common name `www.oracle.com' doesn't match requested host name `edelivery.oracle.com'.
To connect to edelivery.oracle.com insecurely, use `--no-check-certificate'.
无法建立 SSL 连接。

好吧,之前装JRE的时候我已经那个碰到这个问题了,不过现在只知道是因为要接受Oracle的一个协议,从而导致的cookie的值不对的问题,至于怎么改……忘了……(旁白:“唉,好记性不如烂博客啊……博主面壁思过中……”)

如下图:

接受协议前的cookie

beforeAccept.png

接受协议后的cookie

afterAccept.png

继续google之,于是再次找到解决方案,决定把它记下来……(旁白:”知错能改,博主好样的……”)

方案如下:

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F" "http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin"

需要注意的是这边的下载地址不是直接右键复制的下载地址,而是有点小改动的

原地址:

http://download.oracle.com/otn/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin

新地址:

http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin

就是把“otn”改成了“otn-pub”;这里不修改的话就会跳转到登录页面,导致还是无法下载,会报错

已发出 HTTP 请求,正在等待回应... 302 Moved Temporarily
位置:https://login.oracle.com/pls/orasso/orasso.wwsso_app_admin.ls_login?Site2pstoreToken=v1.2~CA55CD32~64064678573E4BFB9492C42D20C407ADD491054099958E28938C6AC537B64BBAD33B672721

修改完之后就搞定下载了

[root@vps java]# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F" "http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin"
--2014-02-18 22:41:37--  http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin
正在解析主机 download.oracle.com... 65.122.127.49, 65.122.127.43
Connecting to download.oracle.com|65.122.127.49|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Moved Temporarily
位置:https://edelivery.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin [跟随至新的 URL]
--2014-02-18 22:41:37--  https://edelivery.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin
正在解析主机 edelivery.oracle.com... 23.214.22.140
Connecting to edelivery.oracle.com|23.214.22.140|:443... 已连接。
WARNING: certificate common name `www.oracle.com' doesn't match requested host name `edelivery.oracle.com'.
已发出 HTTP 请求,正在等待回应... 302 Moved Temporarily
位置:http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin?AuthParam=1392734704_57f061bd9ccab9f260f07f0140aae83c [跟随至新的 URL]
--2014-02-18 22:41:37--  http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin?AuthParam=1392734704_57f061bd9ccab9f260f07f0140aae83c
Reusing existing connection to download.oracle.com:80.
已发出 HTTP 请求,正在等待回应... 200 OK
长度:71799552 (68M) [application/octet-stream]
Saving to: `jdk-6u45-linux-i586.bin?AuthParam=1392734704_57f061bd9ccab9f260f07f0140aae83c'

100%[======================================>] 71,799,552  7.52M/s   in 7.6s    

2014-02-18 22:41:45 (9.05 MB/s) - `jdk-6u45-linux-i586.bin?AuthParam=1392734704_57f061bd9ccab9f260f07f0140aae83c' saved [71799552/71799552]

下载完成后,执行这个bin

[root@vps java]# chmod +x jdk-6u45-linux-i586.bin
[root@vps java]# ./jdk-6u45-linux-i586.bin
Unpacking...
Checksumming...
Extracting...

最后设置环境变量

JAVA_HOME=/usr/local/java/jdk1.6.0_45
CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin
export JAVA_HOME JAVA_BIN PATH CLASSPATH