To run Java code on a Gentoo system you must have a JRE (Java Runtime Environment) installed. The JRE will install a 32-bit browser plugin, among other things, which is necessary to take advantage of Java applets in Firefox.
Before we go any further, it must be noted that this will only work with the 32-bit version of Firefox. This is because the binary JRE package is only distributed in 32-bit and is therefore incompatible with the 64-bit version of Firefox. If you run a 64-bit system make sure that you have emerged the www-client/mozilla-firefox-bin package to get the 32-bit browser.
There are numerous JRE packages within portage, but the recommended package to emerge is dev-java/sun-jre-bin. Don’t confuse the JRE with JDK (Java Development Kit) which will add unnecessary Java programming tools to the installation.
To get the browser plugin you must enable the nsplugin USE flag when emerging the JRE. You can add this to your global USE flags by placing it directly into the make.conf file.
If you don’t want every package capable of installing a plugin to do so, you can limit the flag to this package only by adding the following entry to /etc/portage/package.use.
dev-java/sun-jre-bin nsplugin
Once the nsplugin flag is set to your liking then go ahead and emerge the JRE.
# emerge -av dev-java/sun-jre-bin
The ‘-v‘ and ‘-a‘ options will allow you view the USE flags that are enabled, and confirm they are correct before allowing it to continue.
If you are running an amd64 system then you will need to emerge the app-emulation/emul-linux-x86-java package as well. This package contains the basic 32-bit libraries needed to run the 32-bit JRE binaries on your 64-bit system.
You will need the nsplugin USE flag enabled for this package as well. If you didn’t add the keyword to your global USE flags in the previous step, add the following entry to /etc/portage/package.use.
app-emulation/emul-linux-x86-java nsplugin
Now emerge the package, again making sure the USE flags are correct.
# emerge -av app-emulation/emul-linux-x86-java
You will now have to configure your system to use the JRE with the eselect command utility.
Use this for a x86 system.
# eselect java-nsplugin set sun-jre-bin-1.6
Use this for an amd64 system.
# eselect java-nsplugin set 32bit emul-linux-x86-java-1.6
Once all of these steps have been completed you can verify that everything is correct by running.
# eselect java-nsplugin list
Available 32-bit Java browser plugins [1] emul-linux-x86-java-1.6 current Available 64-bit Java browser plugins
Check that Firefox has found the plugin by opening up a new window and entering about:plugins in the address bar. You should now see the Java plugin listed.