title: Builds failing after upgrading to Java7, Missing Tools.jar and bad class versions
body: <p>I recently upgraded to Java7 on my Macbook Pro.  I downloaded the JDK (not the JRE).</p>
  
  <pre><code>» javac version
  javac 1.7.0_17
  
  » echo $JAVA_HOME    
  /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home
  </code></pre>
  
  <p>However, when trying to run a build, one of the maven compiler plugins is failing, claiming I have a JRE installed:</p>
  
  <pre><code>» mvn install
  [ERROR] execute error
  org.apache.maven.plugin.MojoExecutionException: You need to run build with JDK
   or have tools.jar on the classpath.
  If this occures during eclipse build make sure you run eclipse under JDK as well
      at com.mysema.maven.apt.AbstractProcessorMojo.execute(AbstractProcessorMojo.java:263)
      at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
  </code></pre>
  
  <p>I'm confused, as I clearly have a JDK installed.  My <code>MAVEN_OPTS</code> don't do anything funny:</p>
  
  <pre><code>» echo $MAVEN_OPTS          
  -Xmx512m
  </code></pre>
  
  <p>Trying to debug, I checked the <a href="http://grepcode.com/file/repo1.maven.org/maven2/com.mysema.maven/maven-apt-plugin/1.0.4/com/mysema/maven/apt/AbstractProcessorMojo.java?av=f#261" rel="noreferrer">source</a> of the plugin in question, which is doing the following:</p>
  
  <pre><code>    try {
          JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
          if (compiler == null) {
              throw new MojoExecutionException("You need to run build with JDK or have tools.jar on the classpath."
                      + "If this occures during eclipse build make sure you run eclipse under JDK as well");
          }
  </code></pre>
  
  <p>That seems harmless, so I suspected something wrong on my command line env, and wrote a simple test:</p>
  
  <pre><code>// Main.java
  import javax.tools.JavaCompiler;
  import javax.tools.ToolProvider;
  
  
  public class Main {
  
      public static void main(String[] args) {
          JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
          if (compiler == null)
          {
              System.out.print("Compiler is null");
          } else {
              System.out.print("Compiler is not null");
          }
      }
  
  }
  
  » javac Main.java
  
  Main.java:1: cannot access javax.tools.JavaCompiler
  bad class file: /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/rt.jar(javax/tools/JavaCompiler.class)
  class file has wrong version 51.0, should be 49.0
  Please remove or make sure it appears in the correct subdirectory of the classpath.
  import javax.tools.JavaCompiler;
                     ^
  1 error
  </code></pre>
  
  <p>If I understand that error correctly, it suggests a Java7 compiler running against a Java5 <code>rt.jar</code>?</p>
  
  <p>I'm not sure what's going on here. </p>
  
  <p>I clearly have a Java7 JDK installed, but don't understand:</p>
  
  <ul>
  <li>Why is the maven plugin is returning null for the compiler?</li>
  <li>Why am I getting class version errors?</li>
  </ul>
  
  <h2>Update</h2>
  
  <p>Answers are suggesting a messed up JRE / JDK install.  I agree this seems likely, but having trouble tracking down where the culprit lies.  </p>
  
  <p>Some additional info:</p>
  
  <pre><code>» which javac
  /usr/bin/javac
  
  ls -ltra /usr/bin/javac
  /usr/bin/javac -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac
  
  cd /System/Library/Frameworks/JavaVM.framework/Versions
  ls -ltra
  
  lrwxr-xr-x   1 root  wheel   10 18 Feb 08:36 1.6.0 -&gt; CurrentJDK
  lrwxr-xr-x   1 root  wheel   10 18 Feb 08:36 1.6 -&gt; CurrentJDK
  lrwxr-xr-x   1 root  wheel   10 18 Feb 08:36 1.5.0 -&gt; CurrentJDK
  lrwxr-xr-x   1 root  wheel   10 18 Feb 08:36 1.5 -&gt; CurrentJDK
  lrwxr-xr-x   1 root  wheel   10 18 Feb 08:36 1.4.2 -&gt; CurrentJDK
  lrwxr-xr-x   1 root  wheel   10 18 Feb 08:36 1.4 -&gt; CurrentJDK
  drwxr-xr-x   8 root  wheel  272 18 Feb 08:39 A
  drwxr-xr-x  11 root  wheel  374 18 Feb 08:39 ..
  lrwxr-xr-x   1 root  wheel    1 14 Jun 11:14 Current -&gt; A
  lrwxr-xr-x   1 root  wheel   58 14 Jun 11:15 CurrentJDK -&gt; /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents
  drwxr-xr-x  11 root  wheel  374 14 Jun 11:15 .
  </code></pre>
  
  <p>So, the javac that is running is the one installed in <code>A/Commands</code>.   I'm not sure if this is correct or not.  It seems wrong from my windows days, but I'm not familiar enough with how Mac treats Java install to go tinkering.</p>
  
  <p>My <code>$JAVA_HOME</code> points to <code>/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home</code>, which has the following:</p>
  
  <pre><code>drwxrwxr-x  10 root  wheel       340  5 Feb 08:10 jre
  -rw-rw-r--   1 root  wheel    123324  5 Feb 08:10 THIRDPARTYLICENSEREADME-JAVAFX.txt
  drwxrwxr-x   5 root  wheel       170  5 Feb 08:10 man
  drwxrwxr-x   9 root  wheel       306  2 Mar 02:10 db
  -rw-rw-r--   1 root  wheel      3339  2 Mar 02:10 COPYRIGHT
  drwxrwxr-x   9 root  wheel       306  2 Mar 02:10 include
  -rw-rw-r--   1 root  wheel  19997030  2 Mar 02:10 src.zip
  -rw-rw-r--   1 root  wheel       447  2 Mar 02:10 release
  -rw-rw-r--   1 root  wheel    172252  2 Mar 02:10 THIRDPARTYLICENSEREADME.txt
  -rw-rw-r--   1 root  wheel       114  2 Mar 02:10 README.html
  -rw-rw-r--   1 root  wheel        40  2 Mar 02:10 LICENSE
  drwxrwxr-x   5 root  wheel       170  2 Mar 02:10 ..
  drwxrwxr-x  15 root  wheel       510  2 Mar 02:13 .
  drwxrwxr-x  13 root  wheel       442  2 Mar 02:13 lib
  drwxrwxr-x  43 root  wheel      1462  2 Mar 02:13 bin
  </code></pre>