特殊:Badtitle/NS100:Java

来自Ubuntu中文
Oneleaf留言 | 贡献2007年5月14日 (一) 00:36的版本
跳到导航跳到搜索

{{#ifexist: :Java/zh | | {{#ifexist: Java/zh | | {{#ifeq: {{#titleparts:Java|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:Java|1|-1|}} | zh | | }}


Prerequisites

/!\ To install proprietary Java, you must have the Multiverse repository enabled. Keep in mind that this repository is different from the backports Multiverse repository. That is, do not simply uncomment the "multiverse" line for backports. Instead, you will need to add "multiverse" to the existing main line in /etc/apt/sources.list.

For more information about the Multiverse repository, please visit the following guide:

Managing Repositories.

Introduction

Java is a technology from Sun Microsystems. There are several implementations, of which four will be talked about here:

  • Free Java: GNU classpath and others, these are already included in Ubuntu as of Ubuntu 5.10. These implementations are available for all supported Ubuntu architectures.
  • Sun Java: Sun Java is the reference implementation. As of Ubuntu 6.06, it is included in multiverse
  • Blackdown Java: Blackdown Java, a port of the Sun JDK to Linux which pre-dates Sun's official port, is included in multiverse of Ubuntu 5.10 and later
  • IBM Java: IBM Java is a reimplementation with a Just-In-Time Compiler. It is only available from IBM's website. It is the preferred Java solution on PowerPC machines, and instructions for Ubuntu on PowerPC are below. It is also available for i386 and AMD64, but use on such installations is not discussed here.

Java is also very different based on your processor architecture. Most computers are i386, Mac are PowerPC (although newer Mac``Books and Mac``Book Pros are i386) and some newer computers are AMD64. Use the following chart to see which version of Java you should install:

<-9:> Release
<-3> Free Java <-3> Proprietary Java
7.04 6.10 6.06 7.04 6.10 6.06
i386 <-3> GCJ <-3> Sun Java
PPC <-3> GCJ <-3> IBM Java
AMD64 <-3> GCJ <-3> Sun Java *
SPARC <-5> GCJ <-5> -


  • There are no browser plugins for AMD64 and sparc. You will need to install a 32bit version of Firefox. See below.
  • Starting with Ubuntu 6.10 (Edgy``Eft), you can install the experimental java-gcj-compat-plugin from the universe archive. It is available on all architectures. Note however, that the plugin currently runs with no security manager. This means that applets you load can do anything a java application that you download and run can do. Be **very** careful which applets you run.

Installing Free Java

Free Java is already installed in the default installation java-gcj-compat. To install the development environment, install the java-gcj-compat-dev package.

Installing Sun Java

Ubuntu 7.04

  • Sun Java6: sun-java6-bin, sun-java6-jre
  • Blackdown Java2 1.4: j2re1.4

Ubuntu 6.06 / 6.10

  • Sun Java5: sun-java5-bin, sun-java5-jre
  • Blackdown Java2 1.4: j2re1.4

Kubuntu 6.06 / 6.10

  • Sun Java5: Load up Konsole, and type:
  sudo apt-get install sun-java5-bin

Accept the licence agreement that appears.

{i} Note: The license may not come up and will cause the package installation to fail, to fix this, do the following:

  In a terminal, type
  sudo apt-get install libqt-perl
  sudo dpkg-reconfigure debconf
  The first command will install the needed package for debconf-kde counterpart.
  The second command will ask a few questions:
  For the first step, choose "kde".
  For the second step, choose "high".
  Then, to fix the packages that did not correctly install, do:
  sudo apt-get -f install
 then you are done.
  • Blackdown Java2 1.4: j2re1.4

{i} Note: Scroll down to "Selecting the default Java version" section to enable the JRE you have installed.

Sun Java SDK (Software Development Kit)

Ubuntu 7.04

  • Sun Java6: sun-java6-jdk

Ubuntu 6.06 / 6.10

  • Sun Java5: sun-java5-jdk

Kubuntu 6.06 / 6.10

  • Sun Java5: Load up Konsole, and type:
  sudo apt-get install sun-java5-jdk

Accept the licence agreement that appears.

  • Blackdown Java2 1.4 packages: Install the j2re1.4 package, available in the multiverse repositories. Install it from the Applications -> Add/Remove... menu, or install the j2re1.4 package.

Selecting the default Java version

If you want to use Sun's Java instead of the open source GIJ (GNU Java bytecode interpreter) you need to set it as default. To list installed JVMs:

update-java-alternatives -l

To select, for example, Sun's JVM as provided in Ubuntu 6.06, run:

sudo update-java-alternatives -s java-1.5.0-sun

You should also edit /etc/jvm and move /usr/lib/jvm/java-1.5.0-sun to the top of JVMs offered.

Adding JDK 1.4 as an alternative

The Blackdown JDK 1.4 does not automatically appear as an alternative upon installation. In order to make it appear, you'll need to create a file such as /usr/lib/jvm/.java-1.4.2-sun.jinfo as described in the man page for update-java-alternatives. Note: the default install location is /usr/lib/j2se/1.4


Manual method: Run:

  sudo update-alternatives --config java

and select your preference from the list.

{i} Note: You probably want to do the same with jar, javac, javadoc, javah, javap and javaws:

  sudo update-alternatives --config jar

To get common java applications (installed using .deb-packages) to run under your JVM of choice, make sure you also edit the JVM configuration file:

  sudo nano /etc/jvm

and add the line:

  /usr/lib/j2sdk1.5-sun

Packages such as ant starts the first JVM found in this file.

Java on Konqueror

You may find that Java is disabled, even though it is set up correctly in the "Configure Konqueror" Dialog. Select "HTML Settings->Java" from the Tools menu to enable it.

Java on Opera

go to: "Tools"->"Preferences"->"Advanced"->"Content"-> check "Enable Java". to ensure it found Java click "Java Option" from the same dialog. the path should be something like "/usr/lib/jvm/java-6-sun-1.6.0.00/jre/lib/i386" for sun java

Java on Mozilla Firefox

Ubuntu 7.04

  • Sun Java6: sun-java6-plugin

Ubuntu/Kubuntu 6.06/6.10

  • Sun Java5: sun-java5-plugin

amd64: Installing the Mozilla/Firefox plugin

As of 2007-01-19, there is only one plugin that works and that is the one included with Blackdown Java 1.4.2 (see above for install instructions). Neither sun-java5-bin nor the recently released Sun Java 1.6 (Mustang), available from sun.com, contain a browser plugin for amd64. To get later versions of Java working with Firefox on amd64, you need to install the 32-bit version of Firefox and run 32-bit Java 1.5 or 1.6. There is an excellent guide by Kilz with fully automated scripts for doing this here: http://www.ubuntuforums.org/showthread.php?t=202537. These scripts also enable 32-bit Flash and 32-bit Mplayer for Realplayer/Quicktime function and is *highly* recommended for amd64 users.

Note: The instructions below for creating a link for the plugin do not need to be carried out if running Ubuntu 6.06 or later amd64 with Blackdown Java and Firefox. But if for any reason you have problems with the plugin (cannot see it listed when navigating to about:config in Firefox) then create the link manually as described below...

Method one:

$ sudo ln -sf /usr/local/j2re-1.4.2/plugin/amd64/mozilla/libjavaplugin_oji.so /usr/lib/mozilla-firefox/plugins/libjavaplugin.so
$ sudo ln -sf /usr/local/j2re-1.4.2/plugin/amd64/mozilla/libjavaplugin_oji.so /usr/lib/mozilla/plugins/libjavaplugin.so

Method two:

$ sudo ln -sf /usr/lib/j2re1.4-blackdown/plugin/amd64/mozilla/libjavaplugin_oji.so /usr/lib/mozilla-firefox/plugins/libjavaplugin.so
$ sudo ln -sf /usr/lib/j2re1.4-blackdown/plugin/amd64/mozilla/libjavaplugin_oji.so /usr/lib/mozilla/plugins/libjavaplugin.so


PowerPC

IBM produces a Java Development Kit (JDK) for its POWER computers, which happens to also work on PPC. They are the only place to make available recent versions of Java for PPC Linux. Their recent versions consist of versions 1.5.0 and 1.4.2 of Java. They also have a 1.3.1 version, but there is no reason to use that. This page will not discuss the use of IBM's 1.3.1 version.

The 1.4.2 JDK is known to work on G3, G4, and G5 Macs, as well as older 604e and 603e Macs. The 1.5.0 JDK is known to work on G3, G4, and G5 Macs, and it is not yet known whether it works on older 604e and 603e Macs. It is not yet known whether either one works on non-Mac PowerPCs. Please update the Wiki if you have more information!

To get IBM's JDK, go to http://www-128.ibm.com/developerworks/java/jdk/linux/download.html, and choose an SDK for 32-bit iSeries/pSeries. Be sure to get the 32-bit version even if you have a G5. You may choose to download both the latest 1.5.0 and 1.4.2 versions and install both if you wish. In any case, periodically check that page for newer Service Releases, and repeat the process described here whenever there is a new one. There is currently no way to keep track of which Service Release you are on under Ubuntu, so make a note of it. As of this writing, SR4 is the latest of the 1.5.0, and SR7 is the latest of the 1.4.2 version. You will have to register before being allowed to download anything. When you reach the download page, download the TGZ version of the SDK.

Installation Process

To use the TGZ with Ubuntu, you have to convert it to a DEB. Make sure you have the tool `make-jpkg` installed from the Multiverse repository (See UbuntuHelp:AddingRepositoriesHowto):

sudo apt-get install java-package

If you are still using Breezy Badger, you will now need to upgrade the version of the package you just installed. To do this, download this file to your desktop and type:

	cd ~/Desktop
	sudo dpkg -i java-package_0.27_all.deb

Now convert the 1.4.2 TGZ and install the resulting DEB:

	make-jpkg IBMJava2-SDK-142.ppc.tgz
	sudo dpkg -i ibm-j2sdk1.4_1.4.2_powerpc.deb

Now convert the 1.5.0 TGZ and install the resulting DEB:

	make-jpkg ibm-java2-sdk-50-linux-ppc.tgz
	sudo dpkg -i ibm-j2sdk1.5_1.5.0_powerpc.deb

Note: The latest version (as of February 1, 2007) of the IBM 1.5 SDK, SR4, is called `ibm-java2-sdk-5.0-4.0-linux-ppc.tgz`. When I tried to install it on Edgy, it returned a `No matching plugin found.` error. I was able to install it successfully by renaming the downloaded file to match the name `ibm-java2-sdk-50-linux-ppc.tgz` before running the `make-jpkg` command.

Note on libraries: the IBM Java binaries depend on `libstdc++5` and `libgtk1.2` packages. In Dapper and later it's possible that these libraries are not installed because they've been replaced by `libstdc++6` and `libgtk2.0`. In this case, `make-jpkg` will give a lot of warnings about not being able to find dependencies for library files. To get the dependencies set correctly (and to get the Java to work at all), make sure you have installed `libstdc++5 `and `libgtk1.2` (either by using Synaptic or from the command line) before issuing the `make-jpkg` command.

To set the new JRE or JDK as the default, you may need to update your Java alternatives. To check your current default, run:

java -version

If you're not happy with what you see, run the following command and, when prompted, choose your preferred Java environment from the list. If update-alternatives tells you that there is only one Java environment, then you'll need to install another version to make a change. If you chose to install both 1.4.2 and 1.5.0 versions, you may run this command at any time to switch the one subsequently opened Java applications will use. The one that the Firefox and Opera web browsers use will be unaffected. Which one the Konqueror web browser uses, and whether or not it would be affected, depends on your KDE system settings.

	sudo update-alternatives --config java

If you installed a 1.4.2 version, regardless of whether or not you installed a 1.5.0 version, and your processor is not a G5, you must perform yet another step to get it to work. For a G3 or G4, use the following command:

	sudo sh -c 'echo "JITC_PROCESSOR_TYPE=6" >> /etc/environment'

For a 604e or 603e, instead use:

	sudo sh -c 'echo "JITC_PROCESSOR_TYPE=5" >> /etc/environment'

You may have to log out or restart the computer for this to take effect.

Note: In the GNOME environment of Ubuntu 6.06 LTS/Dapper Drake, it may be possible that changing language selections may overwrite this file, causing a 1.4.2 version of IBM Java to stop working completely. Please share such experiences, if any, on this wiki.

IF you installed the JDK, the following code tests that everything's working. Open a terminal, and try this for version 1.4.2:

	cd /usr/lib/j2sdk1.4-ibm/demo/applets/TicTacToe
	../../../bin/appletviewer example1.html

To try version 1.5.0:

	cd /usr/lib/j2sdk1.5-ibm/demo/applets/TicTacToe
	../../../bin/appletviewer example1.html

If you see a Tic Tac Toe game, it worked! If you installed the JRE, you don't have an appletviewer or any demos so try whichever program it was that led you to install java in the first place!

Neither the Firefox web browser nor the full Mozilla suite can use version 1.4.2, but they can use 1.5.0 if you configure as follows:

	mkdir -p ~/.mozilla/plugins
	cd ~/.mozilla/plugins
	ln -s /usr/lib/j2sdk1.5-ibm/jre/bin/libjavaplugin_oji.so

To control which Java the Konqueror web browser uses, go to your KDE system settings. Select Internet & Network -> Web Browser -> Java & JavaScript, and change the Path to Java executable to either /usr/lib/j2sdk1.4-ibm/bin/java or /usr/lib/j2sdk1.5-ibm/bin/java.

To control which Java the Opera web browser uses, go to Tools -> Preferences -> Advanced -> Content -> Java options, and change the path to either /usr/lib/j2sdk1.4-ibm/jre/bin or /usr/lib/j2sdk1.5-ibm/jre/bin.

Test the installation at the Sun Java test webpage.

work-arounds

ppc: bug #343837

? ln -s /usr/lib/j2sdk1.5-ibm/jre/bin/libjavaplugin_oji.so /usr/lib/mozilla-firefox/plugins ?

Kubuntu 6.10

bug #69766

  • Sun Java5

The instructions for 6.06 are still valid in Kubuntu 6.10. If you have attempted to install sun java packages using adept you may experience problems. Adept hangs at the point where it should display the license agreement. This is a bug in adept. If you press the 'show details' button the license agreement is visible in the background but OK cannot be selected. This is the work around: In a terminal type:

  ps -e | grep adept

You should see output like this

  4692 ?        00:00:08 adept_notifier
  7228 ?        00:00:02 adept_manager

Type this command

  sudo kill 7228

The number will be different each time. Then use the instructions for kubuntu 6.06 to install java from the commandline. it may be necessary to issue this command first

  sudo dpkg --configure -a

CategoryDocumentation CategoryCleanup