Java Installation Help
From Gentoo Linux Wiki
| Terminals / Shells • Network • X Window System • Portage • System • Filesystems • Kernel • Other |
Contents |
[edit] Removing a Sun JRE/JDK installed using the Sun .bin installer
Installing a JRE/JDK using the Sun installer will cause problems. It's heavily recommended that you use portage to install a JRE/JDK. In case you weren't aware of this, here are instructions for removing everything the installer installed.
We are going the use a wonderful script called cruft to remove anything not installed by ebuilds. Cruft will not only remove the JRE/JDK you installed but will also clean other useless files. To use cruft follow the article here in the wiki: using cruft. If you don't want to remove anything else than the JRE/JDK, you have two options 1)just remove the other lines from the cruft.out file, and 2)grep the java lines to remove as follows:
# grep java cruft.out | xargs rm -rf
After you have removed the JRE/JDK you are ready to install using emerge.
[edit] Installing a JRE/JDK
Just follow the official java guide at gentoo.org:
[edit] Java 1.5
Running gentoo with Java 1.5 requires that Java 1.4.2 be installed as well - see Java FAQ for details.
The J2SE 5.0 compiler by default is not compatibile with pre 1.5 source, to maintain backwards compatibility the -source and -target flags are available. Many build scripts for java packages in portage do not take the -source and -target flags into consideration (as of September, 2008); until the issues are resolved dev-java/sun-jdk-1.5.* is masked.
Since gentoo allows multiple Java implementations on a system via java-config 1.4 and 1.5 can coexist.
unmask:
# echo "dev-java/sun-jdk ~x86" >> /etc/portage/package.keywords # echo "dev-java/java-sdk-docs ~x86" >> /etc/portage/package.keywords # echo "dev-java/sun-jdk" >> /etc/portage/package.unmask # echo "dev-java/java-sdk-docs" >> /etc/portage/package.unmask # echo "dev-java/java-config ~x86" >> /etc/portage/package.keywords # echo "dev-java/java-config-wrapper ~x86" >> /etc/portage/package.keywords
If the above does not work, simply create a file /etc/portage/package.keywords, and place "dev-java/sun-jdk ~x86" in it. Same thing for the second line.
emerge:
# emerge sun-jdk
view installed java kit:
| Code: java-config -L |
[sun-jdk-1.5.0.01] "Sun JDK 1.5.0.01" (/etc/env.d/java/20sun-jdk-1.5.0.01) * [sun-jdk-1.4.2.07] "Sun JDK 1.4.2.07" (/etc/env.d/java/20sun-jdk-1.4.2.07) |
suppose you emerge a java-based package and it fails (usually because of the new enum keyword) we can switch back to Java 1.4 temporarily:
| Code: java-config -S sun-jdk-1.4.2.07 |
System Virtual Machine set
You may want to update your enviroment by running:
"/usr/sbin/env-update && source /etc/profile"
|
# /usr/sbin/env-update && source /etc/profile
Re-emerge the package and it should compile properly. Afterwards set the system Java back to 1.5.
- This doesn't seem to work for every package, I had problems compiling dev-java/commons-net-1.2.2-r1 with java 1.5.0 due to enum keywords, switched to 1.4.2.07 and had code version conflicts, I solved the problem by editing the ant build file (build.xml) -> adding source="1.4" to every javac call gives many deprecated and enum-keyword warnings but works: -fhofmann
- Using Java packages compiled with 1.4 and 1.5 on the same system is destined to give problems. Many libraries include ant-tasks. These tasks cannot be loaded when compiled with 1.5, while ant is using 1.4. Therefore I recommend to always use 1.4 when emerging packages. It is safe however to use 1.5 for applications. -Emond Papegaaij
ebuild <ebuild of java build> fetch unpack vim <path to build.xml> < add source="1.4" to every javac call > ebuild compile install qmerge
[edit] References
Gentoo Linux Documentation - Mixing Software Branches -- Explains how to unmask packages.
