Monday Nov 28, 2011

Build Open JDK 7 on Mac OSX (TOTD #172)

The complete requirements, pre-requisites, and steps to build OpenJDK 7 port on Mac OSX are described here. The steps are very clearly explained and here are the exact ones I followed on my MacBook Pro 10.7.2:
  1. Confirm the version of pre-installed Java as:
    > java -version
    java version "1.6.0_26"
    Java(TM) SE Runtime Environment (build 1.6.0_26-b03-383-11A511c)
    Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-383, mixed mode)
  2. Download and install Mercurial from (zip bundle for 10.7 is here). It gets installed in the /usr/local/bin directory.
  3. Get the source code as (commands highlighted in bold):

    hg clone
    destination directory: macosx-port
    requesting all changes
    adding changesets
    adding manifests
    adding file changes
    added 437 changesets with 364 changes to 33 files
    updating to branch default
    31 files updated, 0 files merged, 0 files removed, 0 files unresolved
    cd macosx-port
    chmod 7555
    # Repos:  corba jaxp jaxws langtools jdk hotspot
    Starting on corba
    Starting on jaxp
    Starting on jaxws
    Starting on langtools
    Starting on jdk
    Starting on hotspot
    # hg clone corba
    requesting all changes
    adding changesets
    adding manifests
    adding file changes
    added 396 changesets with 3275 changes to 1379 files

    . . .

    # exit code 0
    # cd ./corba && hg pull -u
    pulling from
    searching for changes
    no changes found
    # exit code 0
    # cd ./jaxp && hg pull -u
    pulling from
    searching for changes
    no changes found
    # exit code 0
  4. Install Xcode from the App Store. Include /Developer/usr/bin in PATH.

    Note: JDK 1.6.0_26 ame pre-installed on my laptop and I installed Xode after that. The compilation went fine and there was no need to re-install the Java for Mac OS X as mentioned in the original steps.
  5. Build the code as:

    ALWAYS_PASS_TEST_GAMMA=true ALT_BOOTDIR=`/usr/libexec/java_home -v
    1.6` HOTSPOT_BUILD_JOBS=`sysctl -n hw.ncpu`

    The final output is shown as:

    >>>Finished making images @ Sat Nov 19 00:59:04 WET 2011 ...
    >>>Finished making images @ Sat Nov 19 00:59:04 WET 2011 ...
    ##### Leaving jdk for target(s) sanity all docs images #####
    ##### Build time 00:17:42 jdk for target(s) sanity all docs images #####

    ## Build times ##########
    Target all_product_build
    Start 2011-11-19 00:32:40
    End 2011-11-19 00:59:04
    00:01:46 corba
    00:04:07 hotspot
    00:00:51 jaxp
    00:01:21 jaxws
    00:17:42 jdk
    00:00:37 langtools
    00:26:24 TOTAL
  6. Change the directory and verify the version:

    >cd build/macosx-universal/j2sdk-image/1.7.0.jdk/Contents/Home/bin
    >./java -version
    openjdk version "1.7.0-internal"
    OpenJDK Runtime Environment (build 1.7.0-internal-arungup_2011_11_19_00_32-b00)
    OpenJDK 64-Bit Server VM (build 21.0-b17, mixed mode)

Now go fix some bugs, file new bugs, or discuss at the macosx-port-dev mailing list.

Monday Nov 01, 2010

TOTD #149: How to clean IntelliJ cache, preferences, etc on Mac OS X ?

I've installed, un-installed, re-installed, re-un-installed, re-re-installed and so on IntelliJ IDEA multiple times on my MacBook. However the uninstall leaves a few remnants in different directories all over the system. These directories need to be manually removed in order for a clean install next time. This TOTD (Tip Of The Day) provide the list of directories which need to be removed explicitly:

~//Library/Application Support/IntelliJIdea90

And IntelliJ IDEA is installed in the directory "/Application/IntelliJIdea90" which gets deleted if the application is deleted. And you'll need to get rid of this directory if the mystical plugin configuration is not configured right the first time.

Also read IDEA-43039 for more details on invalidating caches. Read more on on how to clear out global settings.

That's it, just a short one this time!

Is there a better way to deal with this mess ?

Technorati: totd intellij idea cache osxtips

Thursday Jun 24, 2010

TOTD #141: Running GlassFish 3.1 on Ubuntu 10.04 AMI on Amazon EC2

GlassFish 3.1 Milestone 2 was released this week, download the zip file.

TOTD #138 provide simple instructions to get you started with Milestone 1 and you can follow similar steps to get started with Milestone 2 as well. A more detailed blog on the new functionality (SSH Provisioning and Dynamic App Deployment) is coming as well.

In order to test the newly added clustering capabilities of GlassFish 3.1, I decided to run Milestone 2 build on a Ubuntu 10.04 instance on Amazon EC2. My host operating system is Mac OS X and even though the steps are defined at multiple locations (mentioned below) but complete set of steps were missing. This Tip Of The Day (TOTD) shows how get started with running a GlassFish 3.1 build on Ubuntu 10.04 instance on Amazon EC2.

This TOTD consulted the following blogs:

Twitterverse was very helpful and Divyen helped smoothen the rough edges!

Lets get started!

  1. In your home directory, create a new ".ec2" directory.
  2. Generate SSH Key & X.509 certificates
    1. Generate X.509 certificates key
      1. Go to your AWS account and click on "Security Credentials".
      2. In "Access Credentials" section, click on "X.509 Certificates" and click on "Create a new Certificate". Make sure to download the private key file and X.509 certificate in ".ec2" directory as "cert-xxxxxx.pem" and "pk-xxxxxxx.pem".
    2. SSH key - Public AMIs can be accessed using an ssh key. Give the following command in ".ec2" directory:
      ec2-add-keypair ec2-keypair > ec2-keypair.pem

      This will generate the SSH key in the file "ec2-keypair.pem".
  3. EC2 API Tools
    1. Download Amazon EC2 API Tools from here and unzip them in ".ec2" directory.
    2. Move "lib" and "bin" directory from the extracted directory to ".ec2" directory.
  4. Create ".ec2.profile" file in ".ec2" directory and add the contents:
    export EC2_HOME=~/.ec2
    export PATH=$PATH:$EC2_HOME/bin
    export EC2_PRIVATE_KEY=`ls $EC2_HOME/pk-\*.pem`
    export EC2_CERT=`ls $EC2_HOME/cert-\*.pem`
    export EC2_URL=

    The last line sets the default zone to US-West-1. The AMI id used later is from this region. Source this file by giving the following command in ".ec2" directory:
    source ".ec2.profile"
  5. On your firewall, authorize port 22 for SSH and 8080 for HTTP access for GlassFish on your firewall as:
    ec2-authorize default -p 22
    ec2-authorize default -p 8080
  6. Run the instance as:
    ec2-run-instances ami-c597c680 -k ec2-keypair
  7. Obtain the public IP address of Ubuntu instance as:
    INSTANCE        i-XXXXXXXX      ami-c597c680       running ec2-keypair     0               m1.small        2010-06-24T16:23:44+0000        us-west-1a      aki-XXXXXXXX    monitoring-disabled      XX-XX-XX-XX   XX-XX-XX-XX

    The address "" is the public IP address and will be used for ssh next.
  8. SSH to the ready Ubuntu instance as:
    ssh -i ec2-keypair.pem

  9. Install JDK 6 on Ubuntu
    1. Add the Ubuntu partner repository as:
      sudo add-apt-repository "deb lucid partner"
    2. Update the list of packages as:
      sudo apt-get update
    3. Install JDK 6 as:
      sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk
    4. Make sure the recently added JDK is at the top of JVM search order by giving the command:
      sudo update-java-alternatives -s java-6-sun
      This command adds "/usr/lib/jvm/java-6-sun" to the top of "/etc/jvm" file.
  10. Install "unzip" package as:
    sudo apt-get install unzip
  11. Download & start GlassFish 3.1
    1. Download GlassFish 3.1 Milestone 2 as:
    2. Unzip the downloaded zip file as:
    3. Start GlassFish as:
      ./glassfishv3/glassfish/bin/asadmin start-domain --verbose
    4. And now your default web page is accessible at "".
  12. Finally terminate the instance as:
    ec2-terminate-instances  i-XXXXXXXX

How are you using GlassFish in the cloud ?

Technorati: totd glassfish ubuntu amazon ec2 cloud osxtips

Wednesday Dec 02, 2009

TOTD #114: How to enable Java Console in Mac OS X, Windows, ... ?

Debugging an applet running with Java plug-in or JNLP application running with Java Web Start in the browser requires the "Java Console" so that debugging messages printed using System.out and System.err can be seen. In Windows, there is a "Show Java Console" menu item in Firefox but clicking it still does not show the console. And this happens because the console window is disabled by default.

However the setting can be easily altered as explained below.

On Mac OS, open "Applications" -> "Utilities" -> "Java Preferences"
On Windows, open "Control Panel" -> "Java"
On any platform, type "javaws -viewer"

Click on the "Advanced" tab to see a window similar to the following on Mac OS X:

And the following on Windows:

Change the "Java Console" setting from "Hide console" to "Show console". Launching your JNLP from the browser next time now will also open the "Java Console" as shown below:

and debugging messages will be nicely printed in the console. Read more about the options displayed in the console here.

Technorati: osxtips windows java console jnlp debugging totd

Monday Oct 19, 2009

MacBook Pro Cycle Count – Too High ?

MacBook Pro Cycle Count means the number of times a battery's entire power is used up. It's formally defined as:

A charge cycle means using all of the battery’s power, but that doesn’t necessarily mean a single charge. For instance, you could use your notebook for an hour or more one day, using half its power, and then recharge it fully. If you did the same thing the next day, it would count as one charge cycle, not two, so you may take several days to complete a cycle.

It can be easily determined by clicking on "Apple", "About This Mac", "More Info...", "Hardware", "Power", "Health Information:". MacBook Pro with a replaceable battery retains 80% of its original capacity after 300 cycles as mentioned here. But in all practical cases, I've heard users replacing the batteries closer to 300 counts. This number goes upto 750 for MacBook Air and 1000 for newer MacBook Pro so there is relief already.

My MBP cycle count hit 283 on Friday and the scary part was "Full charge capacity" was down to 258 mAh. In usage terms, a fully charged battery was getting drained out in 10 minutes :(

A new battery was rushed, installed and the new count is certainly the expected number:

Here are some more relevant docs:

Technorati: osxtips battery cyclecount

Monday Sep 28, 2009

TOTD #106: How to install Oracle Database 10g on Mac OS X (Intel) ?

This Tip Of The Day (TOTD) will explain how to install Oracle Database 10g on Mac OS X.

The official documentation is available here and is very well suited for folks with lots of time and patience. But all I wanted was to install Oracle database server up & running on my localhost so that I can start experimenting with it. All my previous entries have used either JavaDB or MySQL so far, but it's about time ;-)

I started preparing a brief tutorial after following the lengthy documentation but then found this excellent blog entry. And realized the content is looking exactly similar :-) Anyway, below are the instructions I followed and additionally also provide a snapshot of the installer windows.

For the brave of heart, complete installation guide is available in HTML and PDF. Read on for an abbreviated, and yet working version, of the instructions.
  1. Download Oracle database 10g R2 ( from here and unzip.
  2. Check hardware/software requirements. (10.5.4+ required)
  3. Create required groups/users (complete details):
    1. Create Oracle inventory group as:

      # dscl . -create /groups/oinstall
      # dscl . -append /groups/oinstall gid 100
      # dscl . -append /groups/oinstall passwd "\*"
    2. Create Oracle software owner as:
      # dscl . -create /users/oracle
      # dscl . -append /users/oracle uid uid_number
      # dscl . -append /users/oracle gid oinstall_gid
      # dscl . -append /users/oracle shell /bin/bash
      # dscl . -append /users/oracle home /Users/oracle
      # dscl . -append /users/oracle realname "Oracle software owner"
    3. Create the home directory for Oracle user as:
      # mkdir /Users/oracle
      # chown oracle:oinstall /Users/oracle
    4. Set the password for Oracle user:
      # passwd oracle
  4. Configure kernel parameters (complete details) by editing "/etc/sysctl.conf" and adding the contents:
    and reboot the machine for these parameters to take effect.
  5. Configure Oracle user's environment (complete details). In the "oracle" user's home directory, create ".bash_profile" and add the following lines:
    export DISPLAY=:0.0
    export ORACLE_BASE=$HOME
    export ORACLE_SID=orcl
    umask 022
    ulimit -Hn 65536
    ulimit -Sn 65536
  6. The "Basic Installation" of "Standard Edition" in an "Interactive" mode can be performed using the "Oracle Universal Installer". This installer is invoked using the script "db/Disk01/runInstaller" (complete details). The screen snapshots are shown below:

    Choose "oracle" as the database password for simplicity.

    and finally click on "Install" to begin the installation.

    Click on "Password Management..." to unlock the sample database user ...

    The output of these scripts look like:
    ~ > sudo /Users/oracle/oraInventory/
    Changing permissions of /Users/oracle/oraInventory to 770.
    Changing groupname of /Users/oracle/oraInventory to oinstall.
    The execution of the script is complete

    ~ > sudo /Users/oracle/product/10.2.0/db_1/
    Running Oracle 10g script ...
    The following environment variables are set as:
         ORACLE_OWNER= oracle
         ORACLE_HOME= /Users/oracle/oracle/product/10.2.0/db_1
    Enter the full pathname of the local bin directory: [/usr/local/bin]:
        Copying dbhome /usr/local/bin ...
        Copying oraenv to /usr/local/bin ...
        Copying coraenv to /usr/local/bin ...
    Creating /etc/oratab file...
    Entries will be added to the /etc/oratab file as needed by
    Database Configuration Assistant when a database is created
    Finished running generic part of script.
    Now product-specific root actions will be performed.

    Click on "Installed Products..." to see the list of Oracle products installed.

  7. There are some more steps before you can start the Oracle listener process.
    1. Edit ".bash_profile" of "oracle" user and add the following settings:
      export ORACLE_HOME=/Users/oracle/oracle/product/10.2.0/db_1
      export PATH=$PATH:$ORACLE_HOME/bin
      Not setting DYLD_LIBRARY_PATH gives the following error:
      ~ oracle$ lsnrctl start
      dyld: Library not loaded: /b/227/network/lib/libnnz10.dylib
        Referenced from: /Users/oracle/oracle/product/10.2.0/db_1/bin/lsnrctl
        Reason: image not found
      Trace/BPT trap
      This was not obvious but Googling helped. Make sure to relogin for these changes to take effect.
    2. If your Mac is using DHCP (most likely) then you may see the error shown below:
      ~ oracle$ lsnrctl start
      LSNRCTL for MacOS X Server: Version - Production on 28-SEP-2009 14:48:49
      Copyright (c) 1991, 2007, Oracle.  All rights reserved.
      Starting /Users/oracle/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...
      TNSLSNR for MacOS X Server: Version - Production
      System parameter file is /Users/oracle/oracle/product/10.2.0/db_1/network/admin/listener.ora
      Log messages written to /Users/oracle/oracle/product/10.2.0/db_1/network/log/listener.log
      Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dhcp-usca14-133-197.SFBay.Sun.COM)(PORT=1521)))
      TNS-12545: Connect failed because target host or object does not exist
       TNS-12560: TNS:protocol adapter error
        TNS-00515: Connect failed because target host or object does not exist
         MacOS X Server Error: 49: Can't assign requested address
      Listener failed to start. See the error message(s) above...

      This error occurs because your MacBook may be running on a different IP address if rebooted after the installation and before starting the server. Fortunately, the error message is very intuitive and it's easy to fix the error by editing "$ORACLE_HOME/network/admin/listener.ora" as shown below:
      # listener.ora Network Configuration File: /Users/oracle/oracle/product/10.2.0/db_1/network/admin/listener.ora
      # Generated by Oracle configuration tools.
        (SID_LIST =
          (SID_DESC =
            (SID_NAME = PLSExtProc)
            (ORACLE_HOME = /Users/oracle/oracle/product/10.2.0/db_1)
            (PROGRAM = extproc)
          (SID_DESC =
            (SID_NAME = orcl)
            (ORACLE_HOME = /Users/oracle/oracle/product/10.2.0/db_1)
      LISTENER =
          (DESCRIPTION =
            (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
            (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

      The changes are highlighted in the bold. Basically, add a new SID referring to "orcl". And for DHCP users the value of HOST key needs to be changed from dynamically assigned IP address to "localhost". Strangely, the Installing on DHCP Computers section of the installation guide says nothing about it :(
    3. Additionally, for DHCP users, you need to change "$ORACLE_HOME/network/admin/tnsnames.ora" as:
      # tnsnames.ora Network Configuration File: /Users/oracle/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
      # Generated by Oracle configuration tools.
      ORCL =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
          (CONNECT_DATA =
            (SERVER = DEDICATED)
            (SERVICE_NAME = orcl)
      The changes are highlighted in bold. And here as well change the value of HOST key to "localhost".
  8. And finally, start the database using SQL\*Plus as:
    ~ oracle$ sqlplus "/ as sysdba"
    SQL\*Plus: Release - Production on Mon Sep 28 17:44:40 2009
    Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
    Connected to an idle instance.
    SQL> startup nomount
    ORACLE instance started.
    Total System Global Area  612368384 bytes
    Fixed Size                  2085872 bytes
    Variable Size             167775248 bytes
    Database Buffers          436207616 bytes
    Redo Buffers                6299648 bytes
    SQL> alter database mount;
    Database altered.
    SQL> alter database open;
    Database altered.
    User altered.
    SQL> exit
    Disconnected from Oracle Database 10g Release - Production
    The last step of unlocking the account should not be required because we explicitly unlocked the account during installation but that apparently didn't work. And I hit ORA-01033, ORA-01034, ORA-12514, ORA-12541, ORA-12547, and ORA-27101 trying different combinations to get the app working.

    Anyway now re-connect to the HR sample database as:
    ~ oracle$ sqlplus hr/hr@orcl
    SQL\*Plus: Release - Production on Mon Sep 28 17:46:19 2009
    Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
    Connected to:
    Oracle Database 10g Release - Production
    SQL> select table_name from user_tables;
    7 rows selected.
    SQL> desc regions;
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     REGION_ID                                 NOT NULL NUMBER
     REGION_NAME                                        VARCHAR2(25)
    SQL> select \* from regions;
    ---------- -------------------------
             1 Europe
             2 Americas
             3 Asia
             4 Middle East and Africa

    Note: If the database is not shutdown properly then it can be forced to do so using the command "shutdown abort" using SQL\*Plus.

A complete archive of all the tips is available here.

Technorati: totd oracle database mac osxtips leopard installation

Wednesday Apr 30, 2008

OSX #8: Java SE 6 U5 on Mac OS X Leopard

Yesterday, Apple released Java SE version 1.6.0_05 for 64-bit Intel-based Mac OS X 10.5.2 or later. Download it here!

It's restricted to 64-bit machines and Charles is unhappy about it. Hopefully, they'll release a 32-bit version as well.

Type "sw_vers" in a terminal to check the Mac OS X version as shown below:
~ >sw_vers
ProductName:    Mac OS X
ProductVersion: 10.5.2
BuildVersion:   9C31
Alternatively, "About This Mac" in the Apple menu shows you the version as well as shown below:

Anyway, after verifying the system requirements, download 57MB bundle and install it following the standard instructions.

And now successfully installed:

It gets installed in "/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0" and shows the version number as:

/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin >./java -version
java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13-120)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_05-b13-52, mixed mode)

The default Java version can be changed by using "Java Preferences" as shown below:
/Applications/Utilities/Java >./"Java Preferences"
The following window shows up:

Pick the version of your choice and that should get you going!

These are the days before JavaOne and all my demos on this machine have been tested using the default J2SE 5. But I'll play with the new release after JavaOne anyway :)

Do you know sign up for GlassFish Day is FREE and gives you access to JavaOne pavilion as well ? Do it now!

A complete archive of all Mac OS X tips on this blog are available here.

Technorati: osxtips mac leopard javase6 javase jdk

Monday Jan 14, 2008

OSX #7: Upgrading Mac OS X from Tiger to Leopard

Did you buy a new or refurbished Macintosh computer on or after Oct 1, 2007 ?
And it does not have Mac OS v10.5 Leopard ?
And would like to upgrade ?
And save money ?

See if you qualify (new or refurbished). If you do, then you can upgrade using a Single-User Upgrade Kit at the cost of $9.95. This offer expires Jan 26, 2008.

Read more details in Mac OS X Leopard Up-to-Date Program.

I ordered mine last week, got the delivery in 3 days and upgraded this morning. Really simple! Now I'm using Mac OS v10.5 Leopad on my MacBook Pro :)

A complete archive of all Mac OS X tips on this blog are available here.

Technorati: mac osxtips tiger leopard

Thursday Jan 03, 2008

OSX #6: Organizing your Dock & Dashboard

Dock is the Windows Start Bar equivalent in MacOS. However if a program is installed on your MacBook, unlike Windows, you'll need to explicitly add it to the Dock.
To add an icon to Dock: Just click on the Finder icon in Dock, Finder Icon, locate the installed program and drag/drop the icon to Dock. This can be done from the Desktop as well.
To remove an icon from Dock: just drag it away from the Dock onto the desktop; the icon will disappear in a poof of smoke Icon deleted from Dock

Mac DashboardDashboard is Windows Sidebar equivalent in MacOS - it is used for hosting widgets and activated by the default keyboard shortcut of F12.  

To add widgets to Dashboard: Some common widgets are included with the OS itself and can be enabled by clicking on the + button in left-bottom corner of the screen when Dashboard is visible. More widgets can be downloaded from here or by clicking on +, "Manage Widgets..." and "More Widgets...". MacBook Dock - Manage Widgets

To remove widgets from Dashboard: Deleting a widget requires you to hold the Option key over a widget which enables a X in the left-top corner of the widget. Just click on the X and the widget will disappear.

A complete archive of all Mac OS X tips on this blog are available here.

Technorati: mac osxtips dock dashboard widgets

Tuesday Dec 25, 2007

OSX #5: Alt-Tabbing in Mac (Switching between windows on Mac)

Alt-Tabbing in Windows shows currently open windows and allows to select one of them which then becomes the active window. If there are 3 Firefox windows, then it'll show 3 icons. A slightly different behavior is available in Mac where it shows one icon for all the open windows of an application and then provide a different keyboard shortcut to switch between all the windows of that application.

Switch between different applications: Command+Tab (for example if you have Firefox, Thunderbird and other applications). Shift+Command+Tab moves in the reverse direction.
Switch between different windows of the same application: Command+~ (for example if you have multiple windows of Firefox). Shift+Command+~ moves in the reverse direction.

However if the application is minimized then it is not activated (which is bizarre)!

If you are holding the command key and hit Q then that particular application will quit, if you hit H then that application will hide (go behind all the applications?).

A complete archive of all Mac OS X tips are available here.

Technorati: mac osxtips


profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.

Java EE 7 Samples

Stay Connected


« July 2016