Posts tagged: leopard

OS X Java Versions

OS X uses a weird and wonderful structure for Java components that allows multiple versions of Java to coexist happily on the same system. Depending on what you want to do, choosing between them can create challenges.

Apple references that were useful compiling this article:

Thanks also go to various others who have already plumbed the mysteries of OS X and Java.

OS X Directory Structure

OS X places all kinds of Java components in the directory structure starting at:

/System/Library/Frameworks

The component that’s of particular interest for this discussion is the JavaVM itself. That structure starts at:

/System/Library/Frameworks/JavaVM.framework

Each distinct Java version has a directory in

/System/Library/Frameworks/JavaVM.framework/Versions

Here’s a sample from my machine

lrwxr-xr-x   1 root  wheel     5B Aug 31 21:35 1.3 -> 1.3.1
drwxr-xr-x   3 root  wheel   102B Jul 20 19:35 1.3.1
lrwxr-xr-x   1 root  wheel     5B Nov 26 03:43 1.5 -> 1.5.0
drwxr-xr-x   8 root  wheel   272B Jan  2  2007 1.5.0
lrwxr-xr-x   1 root  wheel     5B Aug 31 21:35 1.6 -> 1.6.0
drwxr-xr-x   8 root  wheel   272B Oct 18 08:31 1.6.0
drwxr-xr-x   9 root  wheel   306B Oct 18 08:31 A
lrwxr-xr-x   1 root  wheel     1B Aug 31 21:35 Current -> A
lrwxr-xr-x   1 root  wheel     3B Aug 31 21:35 CurrentJDK -> 1.6

There are several interesting points about the subdirectories managed here.

  • The primary release (e.g ’1.5′) is always a link to the corresponding current ‘dot’ or ‘subrelease’ for that version (e.g ’1.5.0′)
  • ‘CurrentJDK’ is linked to whatever is the currently active Java JDK Version
  • ‘Current’ is linked to the currently selected Java SE version

There are several levels of indirection involved. You can stop here if you don’t need a further information or a bad headache. In this excursion, I’ll deal with the 1.6 (Java 6) trajectory.

  • ‘./Current’ is linked to ‘./A’
    • ‘./A’ appears to encompass both Java SE elements and Java JDK elements
    • ‘./A/Commands’ appears to contain JSE binaries
    • ‘./A/Headers’  appears to contain JDK headers
  • ‘./1.6.0′ links to ‘/System/Library/Frameworks/JavaVM.framework/Home’
    • ‘Home’  appears to have JDK binaries fot the specified (default?) version  (debug versions?)

This all serves to set the scene for the most interesting link from the point of view of daily use – ‘/Library/Java/Home’:

/Library/Java/Home -> /System/Library/Frameworks/JavaVM.framework/Home
/System/Library/Frameworks/JavaVM.framework/Home ->
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home

This is the directory that Apple recommends using to set the ‘JAVA_HOME’ variable – beloved of the Java world, and required to get almost anything Java-based to work.

export JAVA_HOME=/Library/Java/Home
export PATH=${JAVA_HOME}/bin:${PATH}

Java Versions

Changes that affect everything on the system

If you want to change the Java version for everything on the system, you can do so with the Java Preferences application

/Applications/Utilities/Java Preferences

On the ‘General’ tab, follow the instructions to change the selection.

osx-javapreferences-general

If the version you want doesn’t appear on the list, you need something more radical (To be supplied).

Changes that affect the specific command you’re running

The Apple-sanctioned way to run a specific Java version from the command line is simple.  This deliberately does not involve changing the Java Preferences.

These changes shown below will only apply for the lifetime of the (bash) shell in which they are used. Using the setup illustrated above for my machine:

export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home
$JAVA_HOME/bin/java

This technique has been tested successfully in two environments:

  • Clean Snow Leopard install – Defaults to Java 1.6 – with manual install of Java 1.5 to run Java 1.5
  • Existing Leopard – default Java 1.5 installation – with manual install of Java 1.6 – to run Java 1.6

Adding a DNS nameserver to OS X Leopard

To add a DNS nameserver to OS X Leopard

Summarized from these excellent articles, Overriding DHCP- or VPN-assigned DNS servers in Mac OS X Leopard, Updating OS X Network Settings to Use a Local DNS Server, and Using a Local DNS Server in Leopard

In OS X (Leopard and later) DNS entries are arranged as a hierarchy – general to specific. You need the most specific applicable entry. Order – general to specific. Output is from scutil list command.

  • State:/Network/Global/DNS
  • Setup:/Network/Service/0/DNS (Fixed Network Adapter)
  • State:/Network/Service/B5DD6BDA-F1B3-40C7-9CEC-03CF97DE7B0A/DNS (Airport Connection)
  • State:/Network/Service/com.cisco.VPN/DNS (CISCO VPN)

So, now for the commands to adjust everything

sudo scutil
list State:/Network/Service/[^/]+/DNS
[Pick the appropriate service]
show State:/Network/Service/com.cisco.VPN/DNS
[
 {
  ServerAddresses :  {
    0 : 10.1.10.211
    1 : 10.1.10.100
  }
}
]
d.init
get State:/Network/Service/com.cisco.VPN/DNS
d.add ServerAddresses 10.1.10.74 10.1.10.211 10.1.10.100
d.show
[
 {
  ServerAddresses :  {
    0 : 10.1.10.74
    1 : 10.1.10.211
    2 : 10.1.10.100
  }
}
]
set State:/Network/Service/com.cisco.VPN/DNS
^D

Remember to flush your local DNS cache after all is said and done:

(Leopard and later) dscacheutil -flushcache

OS X Leopard – Advanced User Settings

In OS X Leopart, ro access advanced user settings:

System Preferences > Accounts > Unlock > Control-Click on User Name > Advanced Settings

Leopard – dscl replaces NetInfo

In Leopard and SnowLeopard, netinfo is gone. It is replaced by the ‘dscl’ (Directory Services Command Line) suite of utilities:

  • dscl – main command-line interface
  • dscacheutil - lookupd replacement
  • dseditgroup
  • dsmemberutil
  • dserr
  • dsexport
  • dsimport
  • dsmemberutil
  • dsperfmonitor

dscl command examples

Interactive mode – defaults to ‘localhost’
dscl
list /

Specifying a datasource – by default the datasource is ‘localhost’. Other datasources require DS proxy support on the remote host.
dscl localhost list /

When specifying a command, you appear to be able to drop the leading ‘-’. You must execute these as root.

List a specific group.
dscl localhost list /Local/Default

List a specific setting for a specific group or set of entries.
dscl localhost list /Local/Default/Users UniqueID

Create a new entry in the local (/) domain under the category /users.
dscl localhost -create /Local/Default/Users/USER

Create and set the user’s ID.
dscl localhost -create /Local/Default/Users/USER UniqueID UNIQUEID

Create and set the shell property to bash.
dscl localhost -create /Local/Default/Users/USER UserShell /bin/bash

Create and set the user’s full name.
dscl localhost -create /Local/Default/Users/USER RealName "USER REAL NAME"

Create and set the user’s group ID property.
dscl localhost -create /Local/Default/Users/USER PrimaryGroupID GROUPID

Create and set the user home directory.
dscl localhost -create /Local/Default/Users/USER NFSHomeDirectory /Local/Users/USER

Set the password.
dscl localhost -passwd /Local/Default/Users/USER PASSWORD

To disable the password, set it to the two characters ‘\*’.

To create a group

dscl localhost -create /Local/Default/Groups GROUP
dscl localhost -append /Local/Default/Groups GROUP PrimaryGroupID GID
dscl localhost -append /Local/Default/Groups GROUP Password \*

WordPress Themes