Java Embedding Plugin Readme (6/2009)

  1. What is the Java Embedding Plugin?
  2. Requirements
  3. Installing and Uninstalling the Binaries
  4. How Does the Java Embedding Plugin Work?
  5. Debugging and Troubleshooting
  6. Known Problems
  7. Building the Java Embedding Plugin
The Java Embedding Plugin was written by Steven Michaud (smichaud at pobox.com)

I) What is the Java Embedding Plugin?

The Java Embedding Plugin is a utility that allows other web browsers than Apple's Safari to use the most recent versions of Java on Mac OS X. When used together with an updated version of Mozilla's MRJ Plugin Carbon (included in this distribution), the Java Embedding Plugin's functionality is currently available to recent versions of Firefox, Seamonkey and Camino. But in principle any web browser could use one of the Java Embedding Plugin's two APIs to add support for Java 1.4.2, J2SE 5.0 and (where available) Java SE 6.

Apple's older Java versions (1.3.1 and earlier) have a documented API for use by browser developers -- the Java Embedding API, exported by the Java Embedding Framework. But Apple has never documented a realistic way for browser developers to support more recent Java versions. (Apple does provide a high-level Web Kit API for use by application developers who want to embed web content in their applications, but existing browsers would have to be completely re-written to use this.) This is an unfortunate state of affairs, and I've decided to do something about it.

The Java Embedding Framework has two APIs -- one for C programmers (suitable for either Carbon or Cocoa browsers) and one for Objective C programmers (suitable for Cocoa browsers). The C API is closely modeled on Apple's Java Embedding API, but with some additions and modifications to fill its gaps and to make it usable with the newer Java versions. (See JavaEmbeddingPlugin.h in the source distribution for more information on the C API. The Objective C API has no documentation yet, and is still changing from version to version.)

To make the Java Embedding Framework usable "out of the box" in at least some existing browers, I've dusted off Mozilla's old MRJ Plugin Carbon, fixed a bunch of bugs, and added support for the Java Embedding Framework.

II) Requirements

The current version (0.9.7.2) of the Java Embedding Plugin and the MRJ Plugin JEP requires Mac OS X 10.4.X or higher. Older versions (0.9.6.5 and earlier) required Mac OS X 10.2.8 or higher. (Dropping support for Mac OS X 10.3.X and 10.2.8 made it possible to greatly simplify building the Java Embedding Plugin from source.)

The Java Embedding Plugin has for the last few years been bundled with current Mac distributions of all the Mozilla.org browsers -- Firefox, Seamonkey and Camino. So if you're using one of these browsers, you don't need to install the Java Embedding Plugin. But you may wish to replace the bundled version of the Java Embedding Plugin with a more recent version (for which see the next section).

III) Installing the Binaries

You don't need to do this unless you're replacing the bundled version of the Java Embedding Plugin (in a Mozilla.org browser) with some other version.

  1. Install the "new" JEP binaries to your computer:
    1. Drag the "new" Java Embedding Plugin binaries (JavaEmbeddingPlugin.bundle and MRJPlugin.plugin) to the /Library/Internet Plug-Ins folder.
    2. If you're running Mac OS X 10.4.X (Tiger), you also need to make sure MRJPlugin.plugin's timestamp is later than the timestamps of two other files in the /Library/Internet Plug-Ins folder -- Java Applet.plugin and Java Applet Plugin Enabler. This isn't necessary on Mac OS X 10.5.X (Leopard).

      Open a Terminal session and enter the following command (which sets MRJPlugin.plugin's "time last modified" to the current time):

      touch "/Library/Internet Plug-Ins/MRJPlugin.plugin"

  2. Remove the "old" JEP binaries from your browser's binary:
    1. Control-click (or right-click) on your browser's binary and choose "Show Package Contents".
    2. Browse to the Contents/MacOS/plugins folder and delete JavaEmbeddingPlugin.bundle and MRJPlugin.plugin.

Mozilla.org browsers always prefer the version of the Java Embedding Plugin in their Contents/MacOS/plugins folder to whatever version (if any) is available in /Library/Internet Plug-Ins.

The versions of JavaEmbeddingPlugin.bundle and MRJPlugin.plugin in /Library/Internet Plug-Ins need to match each other. So do the versions of these two binaries in your browser's Contents/MacOS/plugins folder. To see either binary's version, control-click (or right-click) on it and choose "Get Info".

IV) How Does the Java Embedding Plugin Work?

The Java Embedding Plugin works at a low level -- the same as that of Apple's old Java Embedding Framework (which still provides Java 1.3.1 functionality on OS X Tiger) and the "OJI Plugin" that Sun makes available with its Java Plugin on other platforms (but which Apple chose not to port). Basically, it uses the (C-based) Java Native Interface to bootstrap the JVM, then uses Java code to create an environment that can host an applet. For Cocoa-based browsers (like Camino and current (3.X) Firefox releases) that's pretty much all that's needed. But more is required to support Carbon-based browsers (like current Seamonkey releases and older (pre-3.0) Firefox releases.

The problem is that all the drawing code in Apple's recent versions (1.4.X and up) of Sun's JVM is Cocoa-based, but the drawing models for Carbon and Cocoa are quite different. Apple does provide a Cocoa-Carbon interface (partially documented in their "Integrating Carbon and Cocoa in your Application". But this is, quite frankly, crawling with bugs, and even Apple tries to discourage people from using it to do anything serious -- i.e. to mix Cocoa and Carbon "widgets" in the same window.

For us to support Java 1.4.X and above in Carbon-based browsers, we must "mix Cocoa and Carbon widgets in the same window". Fortunately I've found workarounds for all the bugs in the Cocoa-Carbon interface that I've been able to diagnose -- I use a combination of Carbon event handlers and subclassed Cocoa "system" classes (via poseAsClass or its equivalent).

The Java Embedding Plugin uses many undocumented APIs in the AppKit Framework and in Apple's Java Virtual Machine (whose code is in the JavaVM Framework). I make no apologies for this -- without it my work would have been impossible. But it means that the Java Embedding Plugin is more likely to break on future releases of OS X and of Apple's JVM than an app that uses only published APIs.

V) Debugging and Troubleshooting

The Java Embedding Plugin is a beta app that heavily depends on undocumented APIs. So there will be problems, and I need your help to fix them. But the Java Embedding Plugin won't suddenly become the cause of all the problems on your computer :-) So you need to work a bit to winnow out the problems that have other causes. Fortunately this is very easy.

If you have a problem with an applet in one of the browsers that the Java Embedding Plugin currently supports (Firefox, Camino or Seamonkey), first look in the following file in your home directory -- ~/Library/Logs/Java Console.log. This file is created by the MRJ Plugin JEP, and contains a record of your most recent Java "session" -- including any Java exceptions that may have occurred. Another way to view Java exceptions is to run the Java Control Panel (Java 1.4.X Plugin Settings in the /Applications/Utilities/Java folder, or Java Preferences in the /Applications/Utilities/Java/J2SE 5.0 or /Applications/Utilities/Java folder) and choose "Show console" (though this will cause less information to be written to Java Console.log).

The Java Embedding Plugin logs to the Java Console whenever it creates an applet (each entry will contain a timestamp and (at least) the text JEP creating applet [name]). If your console log doesn't contain one or more recent entries for applets created, then either they weren't loaded or the current page doesn't contain any applets.

If it's really an applet that you're having trouble with, try the same applet in the other supported browsers and in Safari, and (if possible) on different platforms (e.g. in some browser on Linux or Windows).

An applet problem that occurs in Safari, Firefox, Camino and Seamonkey, but not on other platforms using the same version of the Sun's Java Plugin, is likely to be a problem with Apple's implementation of Sun's JVM. A problem that also occurs on other platforms using Sun's Java Plugin is likely to be a problem with Sun's JVM ... or even possibly with your applet :-)

An applet problem that occurs in Seamonkey 1.X and Firefox 2.X but not in Firefox 3.X or Camino is likely to be caused by a problem in the Carbon-specific code of the Java Embedding Plugin. Likewise an applet problem that occurs in Firefox 3.X and Camino but not in Seamonkey 1.X or Firefox 2.X is likely to be caused by something in the Cocoa-browser-specific code of the Java Embedding Plugin.

If possible, try the applet on different versions of Mac OS X. I've seen some Apple-specific problems (i.e. ones not found in similar versions of Sun's JVM on other platforms) disappear with the change from Mac OS X 10.3.X to 10.4.X, or from 10.4.X to 10.5.X.

If the problem isn't associated with a Java applet, it's likely not to have anything to do with Java or the Java Embedding Plugin :-)