安装IBM JDK
对于jdk有很多种选择,可以通过emerge -s jdk列出,我的环境以IBM产品为主,因此选择安装ibm jdk,其已经包含在Gentoo官方ebuild中,可以直接emerge,但jdk安装文件因为license 问题没有放入Gentoo mirror,需要自己下载,手工放入Portage,再继续emerge。
ibm jdk 目前最新版本是1.5(也称为 5.0),下面会安装此版本,为了兼容性,jdk 1.4.2 也一并安装,如果愿意,再安装1.3.1 也不是问题,Gentoo 的java 环境控制非常方便。
以上jdk 在IBM Java download 可以找到,页面中包含各个版本,选择32-bit xSeries (Intel compatible)平台,tar/tgz 格式的文件下载。下载时需要登录ibm.com,如果还没有帐户可以免费注册(前段时间IBM 已经将各语言版本的ibm.com 帐户统一)。
USE flag
USE flag 中加入java 与nsplugin ,没有nsplugin支持,基于浏览器的java applet 无法使用。
jdk 1.5
直接emerge 会出错:
# emerge -av =ibm-jdk-bin-1.5.0.5a
或者
# emerge -av ibm-jdk-bin
These are the packages that would be merged, in order: Calculating dependencies... done! [ebuild RF ] dev-java/ibm-jdk-bin-1.5.0.5a USE="X alsa nsplugin -doc -examples -javacomm" 61,611 kB Total: 1 package (1 reinstall), Size of downloads: 61,611 kB Fetch Restriction: 1 package (1 unsatisfied) Would you like to merge these packages? [Yes/No] >>> Verifying ebuild Manifests... >>> Emerging (1 of 1) dev-java/ibm-jdk-bin-1.5.0.5a to / !!! dev-java/ibm-jdk-bin-1.5.0.5a has fetch restriction turned on. !!! This probably means that this ebuild's files must be downloaded !!! manually. See the comments in the ebuild for more information. * Due to license restrictions, we cannot redistribute or fetch the distfiles * Please visit: http://www.ibm.com/developerworks/java/jdk/linux/download.html * Under J2SE 5.0, download SR5 for your arch: * (note that we switched to tgz format because it's now versioned) * ibm-java2-sdk-5.0-5.1-linux-i386.tgz * You can use direct link to your arch download page: * https://www14.software.ibm.com/webapp/iwm/web/preLogin.do?source=sdk5&S_PKG=intel5sr5a&S_TACT=105AGX05&S_CMP=JDK * Place the file(s) in: /usr/portage/distfiles * Then restart emerge: 'emerge --resume' * Note: if SR5 is not available at http://www.ibm.com/developerworks/java/jdk/linux/download.html * it may have been moved to http://www.ibm.com/developerworks/java/jdk/linux/older_download.html. Lately that page * isn't updated, but the files should still available through the * direct link to arch download page. If it doesn't work, file a bug. * Fetch failed for 'dev-java/ibm-jdk-bin-1.5.0.5a' * Messages for package dev-java/ibm-jdk-bin-1.5.0.5a: * Fetch failed for 'dev-java/ibm-jdk-bin-1.5.0.5a'
自己从ibm.com下载,保存为 /usr/portage/distfiles/ibm-java2-sdk-5.0-5.1-linux-i386.tgz,再次执行emerge ,安装成功。
jdk 1.4.2
与jdk 1.5 相同,同样需要自己下载,保存为 /usr/portage/distfiles/IBMJava2-SDK-1.4.2-9.0.tgz,指定版本执行emerge。
# emerge -av =ibm-jdk-bin-1.4.2.9
java 环境切换
Gentoo Linux 允许不同版本的Java 环境共存,支持对系统和用户级别java 环境的独立控制,提供方便的机制对其进行管理,实现即时切换。有以下2种工具可以利用:
- java环境配置工具java-config
- 系统命令eselsect
通过以下命令,可以实现java环境动态切换,任何已存在的session 无需重新登录或者重新执行profile,新的环境设定会即刻生效。
注意:带# 提示符的命令需要在root 权限下执行。
java-config
$ java-config -L
The following VMs are available for generation-2:
1) IBM JDK 1.4.2.9 [ibm-jdk-bin-1.4]
*) IBM JDK 1.5.0.5a [ibm-jdk-bin-1.5]
$ java-config -s 1
Now using ibm-jdk-bin-1.4 as your user JVM
# java-config -S 1
Now using ibm-jdk-bin-1.4 as your generation-2 system JVM
eselect
eselect 命令也可以做以上工作。
$ eselect java-vm list
Available Java Virtual Machines:
[1] ibm-jdk-bin-1.4
[2] ibm-jdk-bin-1.5 system-vm user-vm
$ eselect java-vm set user 1 # eselect java-vm set system 1


