title: Unsupported Class Version during Maven build in Jenkins
body: <p>I've seen a few of these questions on here, but none of the solutions/tips seem to be pointing me in the right direction. So I have 3 JDK's installed in the locations of "/opt/java/6", "/opt/java/7", and "/opt/java/8". All of these are set in the global Jenkins configuration. Jenkins itself is run using Java 8 which is the system default JRE that I set manually through alternatives (I'm using CentOS 7). I had a bunch of old projects that are built using maven and the maven compiler plugin which is set to source=1.6 target=1.6 . Every time I try to execute a build with the Java 6 JDK I get </p>
  
  <blockquote>
    <p><code>Started by user Antony Prince</code><br>
    <code>ln builds/lastSuccessfulBuild /var/lib/jenkins/jobs/BitCalculator/lastSuccessful failed</code><br>
    <code>java.nio.file.DirectoryNotEmptyException: /var/lib/jenkins/jobs/BitCalculator/lastSuccessful</code><br>
    <code>at sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:242)</code><br>
    <code>at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:108)</code><br>
    <code>at java.nio.file.Files.deleteIfExists(Files.java:1165)</code><br>
    <code>at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)</code><br>
    <code>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)</code><br>
    <code>at java.lang.reflect.Method.invoke(Method.java:483)</code><br>
    <code>at hudson.Util.createSymlinkJava7(Util.java:1194)</code><br>
    <code>at hudson.Util.createSymlink(Util.java:1112)</code><br>
    <code>at hudson.model.Run.createSymlink(Run.java:1851)</code><br>
    <code>at hudson.model.Run.updateSymlinks(Run.java:1832)</code><br>
    <code>at hudson.model.Run.execute(Run.java:1743)</code><br>
    <code>at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:529)</code><br>
    <code>at hudson.model.ResourceController.execute(ResourceController.java:89)</code><br>
    <code>at hudson.model.Executor.run(Executor.java:240)</code><br>
    <code>ln builds/lastStableBuild /var/lib/jenkins/jobs/BitCalculator/lastStable failed</code><br>
    <code>java.nio.file.DirectoryNotEmptyException: /var/lib/jenkins/jobs/BitCalculator/lastStable</code><br>
    <code>at sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:242)</code><br>
    <code>at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:108)</code><br>
    <code>at java.nio.file.Files.deleteIfExists(Files.java:1165)</code><br>
    <code>at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)</code><br>
    <code>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)</code><br>
    <code>at java.lang.reflect.Method.invoke(Method.java:483)</code><br>
    <code>at hudson.Util.createSymlinkJava7(Util.java:1194)</code><br>
    <code>at hudson.Util.createSymlink(Util.java:1112)</code><br>
    <code>at hudson.model.Run.createSymlink(Run.java:1851)</code><br>
    <code>at hudson.model.Run.updateSymlinks(Run.java:1833)</code><br>
    <code>at hudson.model.Run.execute(Run.java:1743)</code><br>
    <code>at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:529)</code><br>
    <code>at hudson.model.ResourceController.execute(ResourceController.java:89)</code><br>
    <code>at hudson.model.Executor.run(Executor.java:240)</code><br>
    <code>Building in workspace /var/lib/jenkins/workspace/BitCalculator</code><br>
    <code>&gt; git rev-parse --is-inside-work-tree # timeout=10</code><br>
    <code>Fetching changes from the remote Git repository</code><br>
    <code>&gt; git config remote.origin.url /home/git/repositories/java/BitCalculator.git # timeout=10</code><br>
    <code>Fetching upstream changes from /home/git/repositories/java/BitCalculator.git</code><br>
    <code>&gt; git --version # timeout=10</code><br>
    <code>&gt; git fetch --tags --progress /home/git/repositories/java/BitCalculator.git +refs/heads/*:refs/remotes/origin/*</code><br>
    <code>&gt; git rev-parse origin/master^{commit} # timeout=10</code><br>
    <code>Checking out Revision 4f119f7783cc4ff00e5bf9bb27850ae7698d4fe8 (origin/master)</code><br>
    <code>&gt; git config core.sparsecheckout # timeout=10</code><br>
    <code>&gt; git checkout -f 4f119f7783cc4ff00e5bf9bb27850ae7698d4fe8</code><br>
    <code>&gt; git rev-list 4f119f7783cc4ff00e5bf9bb27850ae7698d4fe8 # timeout=10</code><br>
    <code>Parsing POMs</code><br>
    <code>[BitCalculator] $ /opt/java/6/bin/java -Djava.awt.headless=true -cp /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-agent-1.5.jar:/usr/share/maven/boot/plexus-classworlds.jar org.jvnet.hudson.maven3.agent.Maven3Main /usr/share/maven /var/lib/jenkins/war/WEB-INF/lib/remoting-2.44.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-1.5.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.5.jar 56445</code><br>
    <code>&lt;===[JENKINS REMOTING CAPACITY]===&gt;channel started</code><br>
    <code>Executing Maven:  -B -f /var/lib/jenkins/workspace/BitCalculator/pom.xml -P sign clean deploy</code><br>
    <code>java.lang.reflect.InvocationTargetException</code><br>
    <code>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)</code><br>
    <code>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)</code><br>
    <code>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)</code><br>
    <code>at java.lang.reflect.Method.invoke(Method.java:597)</code><br>
    <code>at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:331)</code><br>
    <code>at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:239)</code><br>
    <code>at org.jvnet.hudson.maven3.agent.Maven3Main.launch(Maven3Main.java:178)</code><br>
    <code>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)</code><br>
    <code>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)</code><br>
    <code>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)</code><br>
    <code>at java.lang.reflect.Method.invoke(Method.java:597)</code><br>
    <code>at hudson.maven.Maven3Builder.call(Maven3Builder.java:134)</code><br>
    <code>at hudson.maven.Maven3Builder.call(Maven3Builder.java:69)</code><br>
    <code>at hudson.remoting.UserRequest.perform(UserRequest.java:118)</code><br>
    <code>at hudson.remoting.UserRequest.perform(UserRequest.java:48)</code><br>
    <code>at hudson.remoting.Request$2.run(Request.java:328)</code><br>
    <code>at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)</code><br>
    <code>at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)</code><br>
    <code>at java.util.concurrent.FutureTask.run(FutureTask.java:138)</code><br>
    <code>at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)</code><br>
    <code>at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)</code><br>
    <code>at java.lang.Thread.run(Thread.java:662)</code><br>
    <code>Caused by: java.lang.UnsupportedClassVersionError: javax/inject/Provider : Unsupported major.minor version 51.0</code><br>
    <code>at java.lang.ClassLoader.defineClass1(Native Method)</code><br>
    <code>at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)</code><br>
    <code>at java.lang.ClassLoader.defineClass(ClassLoader.java:615)</code><br>
    <code>at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)</code><br>
    <code>at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)</code><br>
    <code>at java.net.URLClassLoader.access$000(URLClassLoader.java:58)</code><br>
    <code>at java.net.URLClassLoader$1.run(URLClassLoader.java:197)</code><br>
    <code>at java.security.AccessController.doPrivileged(Native Method)</code><br>
    <code>at java.net.URLClassLoader.findClass(URLClassLoader.java:190)</code><br>
    <code>at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:386)</code><br>
    <code>at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)</code><br>
    <code>at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)</code><br>
    <code>at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)</code><br>
    <code>at org.jvnet.hudson.maven3.launcher.Maven3Launcher.main(Maven3Launcher.java:86)</code><br>
    <code>... 22 more</code><br>
    <code>channel stopped</code><br>
    <code>[BitCalculator] $ /bin/sh -xe /tmp/hudson6524656470722686910.sh</code><br>
    <code>+ rm 'target/*no_deps*'</code><br>
    <code>rm: cannot remove 'target/*no_deps*': No such file or directory</code><br>
    <code>Build step 'Execute shell' marked build as failure</code><br>
    <code>ERROR: Failed to parse POMs</code><br>
    <code>hudson.util.IOException2: java.lang.reflect.InvocationTargetException</code><br>
    <code>at hudson.maven.Maven3Builder.call(Maven3Builder.java:178)</code><br>
    <code>at hudson.maven.Maven3Builder.call(Maven3Builder.java:69)</code><br>
    <code>at hudson.remoting.UserRequest.perform(UserRequest.java:118)</code><br>
    <code>at hudson.remoting.UserRequest.perform(UserRequest.java:48)</code><br>
    <code>at hudson.remoting.Request$2.run(Request.java:328)</code><br>
    <code>at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)</code><br>
    <code>at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)</code><br>
    <code>at java.util.concurrent.FutureTask.run(FutureTask.java:138)</code><br>
    <code>at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)</code><br>
    <code>at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)</code><br>
    <code>at java.lang.Thread.run(Thread.java:662)</code><br>
    <code>Caused by: java.lang.reflect.InvocationTargetException</code><br>
    <code>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)</code><br>
    <code>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)</code><br>
    <code>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)</code><br>
    <code>at java.lang.reflect.Method.invoke(Method.java:597)</code><br>
    <code>at hudson.maven.Maven3Builder.call(Maven3Builder.java:134)</code><br>
    <code>... 10 more</code><br>
    <code>Caused by: java.lang.Exception: java.lang.reflect.InvocationTargetException</code><br>
    <code>at org.jvnet.hudson.maven3.agent.Maven3Main.launch(Maven3Main.java:181)</code><br>
    <code>... 15 more</code><br>
    <code>Caused by: java.lang.reflect.InvocationTargetException</code><br>
    <code>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)</code><br>
    <code>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)</code><br>
    <code>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)</code><br>
    <code>at java.lang.reflect.Method.invoke(Method.java:597)</code><br>
    <code>at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:331)</code><br>
    <code>at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:239)</code><br>
    <code>at org.jvnet.hudson.maven3.agent.Maven3Main.launch(Maven3Main.java:178)</code><br>
    <code>... 15 more</code><br>
    <code>Caused by: java.lang.UnsupportedClassVersionError: javax/inject/Provider : Unsupported major.minor version 51.0</code><br>
    <code>at java.lang.ClassLoader.defineClass1(Native Method)</code><br>
    <code>at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)</code><br>
    <code>at java.lang.ClassLoader.defineClass(ClassLoader.java:615)</code><br>
    <code>at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)</code><br>
    <code>at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)</code><br>
    <code>at java.net.URLClassLoader.access$000(URLClassLoader.java:58)</code><br>
    <code>at java.net.URLClassLoader$1.run(URLClassLoader.java:197)</code><br>
    <code>at java.security.AccessController.doPrivileged(Native Method)</code><br>
    <code>at java.net.URLClassLoader.findClass(URLClassLoader.java:190)</code><br>
    <code>at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:386)</code><br>
    <code>at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)</code><br>
    <code>at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)</code><br>
    <code>at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)</code><br>
    <code>at org.jvnet.hudson.maven3.launcher.Maven3Launcher.main(Maven3Launcher.java:86)</code><br>
    <code>... 22 more</code><br>
    <code>Archiving artifacts</code><br>
    <code>Sending e-mails to: antony@blazrsoft.com</code><br>
    <code>Finished: FAILURE</code>   </p>
  </blockquote>
  
  <p>This indicates that there's Java 7 interfering somewhere, but I'm not sure where.
  The code is 1.6 compliant and most of the projects have no dependencies, so I'm not sure why this is happening. If I execute maven outside of Jenkins, the projects build just fine with JDK 6, so its leading me to think there's a misconfiguration in Jenkins somewhere, but I'm not sure where since everything seems to be as it should be. The paths to the JDKs are set properly in the global config and the projects themselves are set to use the specified JDK's. I apologize if its a duplicate question or something silly, but I've been trying to figure this out for days with no results. Everyone just says to check the paths and make sure there are no dependent artifacts built with a later JDK and I'm sure that this is not the problem.</p>
  
  <p><code>$ mvn -version</code><br>
  <code>Apache Maven 3.0.5 (Red Hat 3.0.5-16)</code><br>
  <code>Maven home: /usr/share/maven</code><br>
  <code>Java version: 1.8.0_20, vendor: Oracle Corporation</code><br>
  <code>Java home: /opt/java/8/jre</code><br>
  <code>Default locale: en_US, platform encoding: ANSI_X3.4-1968</code><br>
  <code>OS name: "linux", version: "2.6.32-openvz-042stab090.5-amd64", arch: "amd64", family: "unix"</code>  </p>
  
  <p><code>&lt;plugin&gt;</code><br>
  <code>&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;</code><br>
  <code>&lt;version&gt;3.1&lt;/version&gt;</code><br>
  <code>&lt;configuration&gt;</code><br>
  <code>&lt;encoding&gt;UTF-8&lt;/encoding&gt;</code><br>
  <code>&lt;source&gt;1.6&lt;/source&gt;</code><br>
  <code>&lt;target&gt;1.6&lt;/target&gt;</code><br>
  <code>&lt;compilerVersion&gt;1.6&lt;/compilerVersion&gt;</code><br>
  <code>&lt;/configuration&gt;</code><br>
  <code>&lt;/plugin&gt;</code>  </p>