Search:  
Gentoo Wiki

Java_Installation_Help

This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other

Contents

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.

Installing a JRE/JDK

Just follow the official java guide at gentoo.org:

Gentoo Java Guide

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 October, 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.

ebuild <ebuild of java build> fetch unpack
vim <path to build.xml>
< add source="1.4" to every javac call >
ebuild compile install qmerge

References

Gentoo Linux Documentation - Mixing Software Branches -- Explains how to unmask packages.

Retrieved from "http://www.gentoo-wiki.info/Java_Installation_Help"

Last modified: Thu, 15 Feb 2007 14:16:00 +0000 Hits: 32,351