Installing OpenGrok on Ubuntu (Java Target Version Error)

Earlier today, I installed Solr on top of OpenJDK 1.6, running Tomcat 6. That went just fine, but I ran into trouble later, when I tried to install OpenGrok, which requires JDK 1.7. When I ran ant, I got this error:

-do-compile:
[javac] Compiling 245 source files to /usr/local/src/OpenGrok/build/classes
[javac] javac: invalid target release: 1.7

This was strange, since at the suggestion of this StackOverflow answer, I put this line after my opening <project> tag of build.xml

And the result was that I was already running 1.7. After a lot of trial and error, I got it to work by running update-alternatives to officially set the java version to 1.7.

sudo update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java

Hopefully this can help out some other Java sysadmin neophytes.