How to prevent openjdk-6-jre-headless from clobbering Oracle JDK installation?

Solution 1:

Answering my own question:

I used https://askubuntu.com/a/55960/23678 to install Oracle JDK. As you can see, these instructions invoke update-alternatives with a priority of 1. When openjdk-6-jre-headless installs itself it sets a priority of 1061 (where a higher priority replaces lower ones).

In order to fix this problem I simply gave Oracle JDK a priority higher than 1061. When openjdk-6-jre-headless installed itself, it no longer clobbered Oracle JDK as the default.

UPDATE: To update OpenJDK's priorities I simply re-ran:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 2000
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 2000
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 2000

with a priority of 2000 instead of 1 (the priority is the last command-line argument).