JavaFXAndJDK6On32BitMacOS

Tech Tip: How to Set Up JDK 6 and JavaFX on 32-bit Intel Macs

Goal: This tutorial shows how to set up JDK 6 and JavaFX on older Intel Macs (old means 32-bit CPUs from around 2006). The problem is that JavaFX requires JDK 6, but Apple only released the Apple JDK 6 for Mac OS X 10.5/Leopard with 64-bit CPUs. We will use the SoyLatte JDK 6 instead. The tutorial also covers how to set up the NetBeans IDE as tool for JDK 6 and JavaFX development on Mac OS X.

Target group: This tutorial is for JDK 6 developers who are stuck on an older system with

  • Mac OS X 10.4/Tiger, or
  • Mac OS X 10.5/Leopard and a 32-bit CPU ("Intel Core").
  • If you run Mac OS X 10.5 on a 64-bit CPU ("Intel Core 2"), the workaround described here is not necessary. You can directly install the Apple JDK 6 ("Java for Mac OS X 10.5"), NetBeans IDE 6.1, and the JavaFX SDK.
  • If you run Mac OS X 10.6 on any (32bit or 64bit) Intel hardware, the workaround described here is not necessary. You can directly install latest JDK 6 version via Software Update.

Requirements: Basic understanding of NetBeans, Java, and how to use the Terminal (X11.app) is required. The command line examples are for the bash shell.

Installing and Testing the SoyLatte JDK 6

Installing SoyLatte

  1. Go to http://landonf.bikemonkey.org/static/soylatte/ and download the Soy Latte binaries.
  2. Double-click the soylatte.tar.bz2 file in the Finder to extract the soylatte directory.
  3. Move the soylatte directory where you want it and remember the path. For example /sw/soylatte16-i386-1.0.2/

Optional tip from Landon Fuller: The Java homes on Macs are in the /System/Library/Frameworks/JavaVM.framework directory. The following symlinks will trick Mac OS and some other applications into using the new JDK.

  1. Create a new directory /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/.
  2. Create a symlink to it named /System/Library/Frameworks/JavaVM.framework/Versions/1.6/.
  3. Create a symlink named /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home that points to the SoyLatte directory.
mkdir /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/
ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/ /System/Library/Frameworks/JavaVM.framework/Versions/1.6
ln -s /sw/soylatte16-i386-1.0.2/ /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home

Downloading Documentation (Optional)

  1. Go to http://java.sun.com/javase/downloads/index.jsp and download Java SE Documentation.
  2. Save the jdk-6-doc.zip in the soylatte16-i386-1.0.2 directory. You will use it later.

Testing

Open the X11.app and set it up to use the new JDK.

Mac:$ export JAVA_HOME=/sw/soylatte16-i386-1.0.2 
Mac:$ export PATH=/sw/soylatte16-i386-1.0.2/bin:$PATH

Test whether you were successful:

Mac:$ echo $PATH
      /sw/soylatte16-i386-1.0.2/bin:/sw/bin:/sw/sbin:/usr/bin:
      /bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/X11R6/bin
Mac:$ java -version
      java version "1.6.0_03-p3"
      Java(TM) SE Runtime Environment (build 1.6.0_03-p3-landonf_03_feb_2008_02_12-b00)
      Java HotSpot(TM) Client VM (build 1.6.0_03-p3-landonf_03_feb_2008_02_12-b00, mixed mode)
Mac:$ which java
      /sw/soylatte16-i386-1.0.2/bin/java
Mac:$ which javac
      /sw/soylatte16-i386-1.0.2/bin/javac

If the terminal replies with the old values /usr/bin/java or java version 1.5.0_13, go back and check whether you missed a step. Don't close this Terminal window before Completing the Set-up: Saving Settings for the Terminal.

You can now use the JDK 6 from the Terminal. Below you will see how to set up the NetBeans IDE to use the JDK 6.

Installing and Testing the JavaFX SDK

You can skip this step if you don't develop JavaFX. If you solely want the JDK 6, continue with setting up the NetBeans IDE below.

Installing the JavaFX SDK

  1. Got to http://java.sun.com/javafx/downloads/ and download the JavaFX SDK.
  2. If you do not already have the NetBeans IDE 6.1, download and install the NetBeans+JavaFX bundle.
  3. To install the JavaFX SDK, open the JavaFX SDK diskimage in the Finder.
  4. If you run the installer from the Finder, and it does not recognize the Soy Latte JDK 6 and refuses to install JavaFX, cancel the installer. Go back to the X11 Terminal window in which you have set up the PATH and JAVA_HOME variables. To make the JavaFX SDK installer see the Soy Latte JDK 6, run it from the command line as follows:
    Mac:$ open "/Volumes/JavaFX SDK/javafx_sdk-1_0-pre1.mpkg"
  5. Go through the installer steps. The Installer puts the JavaFX SDK into /System/Library/Frameworks/JavaFX.framework/Versions/Current. No extra PATH setup is needed to use it.

Testing

Test whether the installation was successful:

Mac:$ which javafx
      /usr/bin/javafx
Mac:$ which javafxc
      /usr/bin/javafxc

Try to compile and run a Hello World application.

Save this code as file Hello.fx

import javafx.application.Frame;
import javafx.application.Stage;
import javafx.scene.geometry.Circle;
import javafx.scene.paint.Color;

Frame {
    title: "Hello World"
    width: 200
    height: 200
    visible: true

    stage: Stage { 
        content:
            Circle {
                centerX: 100, centerY: 100
                radius: 40
                fill: Color.YELLOW
            }
    }
}

Run it in the terminal:

Mac:$  javafxc Hello.fx 
Mac:$  ls
       Hello$Intf.class    Hello.class    Hello.fx
Mac:$  javafx Hello

If you see the HelloWorld application, you have successfully configured JavaFX for the Terminal. Below you will see how to set up the NetBeans IDE to develop JavaFX applications.

Setting up the NetBeans IDE for JDK 6 and JavaFX

If you want to run the NetBeans IDE 6.1 on JDK 6, start it with the following command (all on one line!) from the X11 terminal:

Mac:$ /Applications/NetBeans/NetBeans\ 6.1.app/Contents/MacOS/netbeans 
         --jdkhome /sw/soylatte16-i386-1.0.2/ 
         --laf javax.swing.plaf.metal.MetalLookAndFeel & 

This forces NetBeans to run on JDK 6 and to use the Metal look and feel (because SoyLatte/X11 does not support the Apple Aqua look and feel). See also warnings regarding X11 below.

Setting up the Netbeans IDE for JDK 6

  1. Go to Tools>Java Platform Manager. JDK 6 should appear as default J2SE platform.
  2. If you are running NetBeans IDE on JDK 1.5, click Add Platform.... Follow the wizard to add the SoyLatte JDK 6 directory as a Java Standard Edition platform.
  3. Optional: Go to the JDK 6's Javadoc tab and add the Java Documentation zip that you downloaded earlier.

Normally in Mac programs, the Exit, About and Options menu items are in the Application menu. With SoyLatte, all Java applications run within X11, and the application menu is owned by the X11.app. So these three important menu items are inaccessble. Thanks to Wangwj for this brilliant hack how to get the menus back:

  1. Open Tools > Plugins, select the Setting tab, and click "Proxy Settings".
  2. This opens the unreachable Options dialog! :) Click "Advanced Options" at the lower left.
  3. Expand "IDE Configuration > Look and Feel > Actions". Locate "System > Exit", "Help > About" and "Window > Options"
  4. For each of the three actions: Right-click and Copy, then expand "Look and Feel > Menu Bar", choose the appropriate target menu (File > Exit, Help > About, Tools > Options), right-click and Paste.
  5. Close the Actions and keep "Look and Feel > Menu Bar" open. Locate and right-click on each of the three added menu items; choose "Move down" to position them where they belong.

The NetBeans IDE is now ready for JDK 6 development on the Mac

Setting up the Netbeans IDE for JavaFX

You can skip this step if you don't develop JavaFX.

  1. Go to http://javafx.netbeans.org/download-compiler-JFXplugin.html and download the JavaFX plugins. Extract the archive to get to the nbm directory.
  2. Go to Tools>Plugins>Downloaded, click Add Plugins... and browse to the .nbm files. Click Install and restart the IDE if asked to.
  3. Go to Tools>Java Platform Manager and click Add Platform...
  4. In the dialog, select "JavaFX platform" and press next.
  5. Java Platform: Make certain this is set to use the Soy Latte JDK 6.
  6. JavaFX SDK folder: Use the Browse button to select .netbeans/6.1/javafx-sdk1.0pre1 (or similar) in your user home directory.
  7. Press finish.

Image:javafx-netbeans-plugins_JavaFXAndJDK6On32BitMacOS.png

The NetBeans IDE is now ready for JavaFX development on the Mac.

Completing the Set-up: Saving Settings for the Terminal

To make the settings permanent for the terminal, add the following lines to your ~/.bash_profile file. (The alias line must be on one line.)

export JAVA_HOME=/sw/soylatte16-i386-1.0.2
export PATH=/sw/soylatte16-i386-1.0.2/bin:$PATH
alias netbeans-jdk6="/Applications/NetBeans/NetBeans\ 6.1.app/Contents/MacOS/netbeans --jdkhome 
/sw/soylatte16-i386-1.0.2/ --laf javax.swing.plaf.metal.MetalLookAndFeel"

Using an IDE for JavaFX development

Image:javafx-netbeans-samples-and-projects_JavaFXAndJDK6On32BitMacOS.png

Make the most of using an IDE:

  • Choose File > New Project > JavaFX to create an empty project, or to try out one of the many sample applications!
  • Open a .jx file and choose Windows > Palette. Drag and drop code snippets (actions, shapes, transformations, animations) from the palette into your app!
  • Click the Preview button above the source code editor to preview GUI components while editing!
  • Press ctrl-space for code completion!

To check whether a JavaFX project is configured correctly, open the project properties and check these two things (in this order):

  1. In the Libraries panel, make certain the project uses the JavaFX Platform.
  2. In the Sources panel, make certain the source level is set to JavaFX on JDK 6.
Image:javafx-jdk6-IDE-32bit-mac_JavaFXAndJDK6On32BitMacOS.png 

Notes and Tips

Warnings

Our custom NetBeans JDK 6 edition looks different from other Mac applications: It runs with a little help from the X11 window system. This workaround has a couple of important side-effects.

  • If you quit X11, or close the terminal window from which you started NetBeans, this will quit NetBeans and you lose unsaved changes!
  • Similarly, closing X11/the terminal will also kill all running JavaFX and Java 6 applications that you started from them!
  • In short: Think of X11 (white box with black X in your dock) as your new NetBeans/Java/JavaFX icon. :-) Don't quit it.
  • Keyboard shortcuts are different in X11: Linux/Windows-like usage of the ctrl key instead of the Apple key. Copy & Paste is done with the mouse buttons: left-select & middle-click.
  • The IDE's menubar will be incomplete (no Quit, no About, no Options) in X11 until you followed this brilliant hack proposed by Wangwj. (Thanks!)

Mac/Java/JavaFX Troubleshooting

How can I tell whether I have Mac OS 10.4 ("Tiger") or Mac OS 10.5 ("Leopard")? 
Apple menu > About this Mac
How can I tell whether my CPU is "Intel Core / 32 bit" or "Intel Core 2 / 64 bit"? 
Apple menu > About this Mac
Should I upgrade to Mac OS 10.5 for JDK6/JavaFX development? 
If you meet the hardware requirements (64-bit CPU!) and there are reasons why you must do Java 6 development on a Mac, then switching to 10.5 saves you a lot of hassle in comparison to 10.4. The only other option you presently have for JavaFX is Windows.
I get UnsupportedClassVersionError when I run apps from the Terminal. 
Make certain you work in a Terminal window (X11.app) with the PATH and JAVA_HOME variables correctly set as described above. The export command does neither affect previously started shells, nor is it permanent (the variables are lost when you close the window).
Why doesn't NetBeans compile/run my JavaFX app? 
Check the project Properties. In the Libraries panel, make certain the project uses the JavaFX Platform. In the Sources panel, make certain the source level is set to JavaFX on JDK 6.
How do I resolve errors about Canvas and and javafx.scene.swing when I compile a sample project? 
The API has changed after the first sample apps were published in 2007. Trash the old sample apps and use the current ones.
Why do some fx files no longer compile or have lots of errors marks since I installed the new SDK?
You may be using out-dated JavaFX plugins (e.g. an old lexer) from before the API change. Uninstall and reinstall all plugins as described above.
What about Java Web Start? 
Sorry, no javaws in SoyLatte.
What to do when NetBeans crashes and it says apple.laf.AquaLookAndFeel not on classpath in the error.log file? 
SoyLatte and X11 do not support the Apple Aqua look and feel, only the Apple JDK 6 does presently. Start NetBeans with the additional option
--laf javax.swing.plaf.metal.MetalLookAndFeel
from the command line to switch to the default look.

Go Forth and Write JavaFX Apps

I add a "DistantLight" with an "azimuth" of 60. I have no idea what that does. I run the app. Wow! Cool! It adds a 3D embossing effect to the circle. I've just accidently created a 3D button that Apple would be proud of. End of Minute 4: I've gone well beyond what I could pull off in basic Swing. An effect like that would require purchasing Filthy Rich Clients or something.
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo