Error when executing “jetty:run” with jetty-maven-plugin version 9 : java.lang.UnsupportedClassVersionError Unsupported major.minor version 51.0

(P) Codever is an open source bookmarks and snippets manager for developers & co. See our How To guides to help you get started. Public bookmarks repos on Github ⭐🙏
Tools involved
- JDK 1.6/1.7
- Eclipse Kepler
- Maven 3.1.1
- m2e – Maven Integration for Eclipse plugin
- Jetty 9
- Windows 7 / 64 bit
Problem
When trying to execute execute the “jetty:run” maven goal from within Eclipse
I am getting the following error:
Error injecting: org.eclipse.jetty.maven.plugin.JettyRunMojo java.lang.TypeNotPresentException: Type org.eclipse.jetty.maven.plugin.JettyRunMojo not present at org.eclipse.sisu.space.URLClassSpace.loadClass(URLClassSpace.java:115) at org.eclipse.sisu.space.NamedClass.load(NamedClass.java:46) at org.eclipse.sisu.space.AbstractDeferredClass.get(AbstractDeferredClass.java:48) at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:86) at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision(InternalFactoryToInitializableAdapter.java:55) at com.google.inject.internal.ProviderInternalFactory$1.call(ProviderInternalFactory.java:70) at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:100) at org.eclipse.sisu.plexus.PlexusLifecycleManager.onProvision(PlexusLifecycleManager.java:133) at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:109) at com.google.inject.internal.ProvisionListenerStackCallback.provision(ProvisionListenerStackCallback.java:55) at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:68) at com.google.inject.internal.InternalFactoryToInitializableAdapter.get(InternalFactoryToInitializableAdapter.java:47) at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:997) at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1047) at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:993) at com.google.inject.Scopes$1$1.get(Scopes.java:59) at org.eclipse.sisu.inject.LazyBeanEntry.getValue(LazyBeanEntry.java:82) at org.eclipse.sisu.plexus.LazyPlexusBean.getValue(LazyPlexusBean.java:51) at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:260) at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:252) at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:459) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:97) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214) at org.apache.maven.cli.MavenCli.main(MavenCli.java:158) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) at org.codehaus.classworlds.Launcher.main(Launcher.java:46) Caused by: java.lang.UnsupportedClassVersionError: org/eclipse/jetty/maven/plugin/JettyRunMojo : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) at java.lang.ClassLoader.defineClass(ClassLoader.java:615) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:389) at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42) at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:242) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227) at org.eclipse.sisu.space.URLClassSpace.loadClass(URLClassSpace.java:107) ... 42 more
I have to mention I had just did an upgrade to JDK 1.7 (without removing the previous JDK 1.6). I thought I did everything right, so here are the steps I took after installing the JDK 1.7:
- set environemnt variables
- add
JAVA_HOME
in environment variables and make it point to the new JDK (e.g. C:\Java\jdk1.7.0_45) - add
%JAVA_HOME%/bin
to thePATH
environment variable
- add
-
made sure Eclipse uses the right JDK: <div id="attachment_1065" style="width: 310px" class="wp-caption alignnone">
Eclipse Menu -> Window -> Preferences -> Java – > Installed JREs
</div></li>
-
pointed to the correct JRE in
eclipse.ini
<pre class="lang:default mark:18,19 decode:true" title="eclipse.ini">-startup plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar –launcher.library plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20130521-0416 -product org.eclipse.epp.package.standard.product –launcher.defaultAction openFile –launcher.XXMaxPermSize 256M -showsplash org.eclipse.platform –launcher.XXMaxPermSize 256m –launcher.defaultAction openFile –launcher.appendVmargs -vm C:/Java/jdk1.7.0_45/bin/javaw.exe -vmargs -Dosgi.requiredJavaVersion=1.6 -XX:MaxPermSize=512m -Xms128m -Xmx1024m</pre> -
made sure the external Maven installation used “sees” the correct JDK by issuing “mvn –version” on the command line: <pre class=”lang:default mark:3,4 decode:true” title=”” mvn=”” –version=”” output=”“>Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 17:22:22+0200) Maven home: C:\Java\apache-maven-3.1.1 Java version: 1.7.0_45, vendor: Oracle Corporation Java home: C:\Java\jdk1.7.0_45\jre Default locale: en_US, platform encoding: Cp1252 OS name: “windows 7”, version: “6.1”, arch: “amd64”, family: “windows” <br></pre></ol>
-
## Solution
The jetty plugin configuration seemed also to be correct in the `pom.xml` file:
<pre class="lang:default decode:true" title="jetty-maven-plugin configuration in pom.xml"><project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> .................................................
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<jettyConfig>${project.basedir}/src/main/resources/config/jetty9.xml</jettyConfig>
<stopKey>STOP</stopKey>
<stopPort>9999</stopPort>
<scanIntervalSeconds>5</scanIntervalSeconds>
<contextXml>${project.basedir}/src/test/resources/jetty-context.xml</contextXml>
<webAppConfig>
<contextPath>/${project.artifactId}-${project.version}</contextPath>
</webAppConfig>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.27</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build> </project></pre>
Then what was the problem? Well, thanks to <a title="java.lang.UnsupportedClassVersionError Unsupported major.minor version 51.0 [duplicate]" href="https://stackoverflow.com/questions/11239086/java-lang-unsupportedclassversionerror-unsupported-major-minor-version-51-0" target="_blank">Stackoverflow</a> I found out the error happens because of a higher JDK during compile time and lower JDK during runtime. But I thought I compiled and executed everything with Java 7…
When checking the JDK compliance for the project:
<div id="attachment_1071" style="width: 304px" class="wp-caption alignnone">
<a href="https://www.codepedia.org/wp-content/uploads/2014/01/3-check-project-jdk-compliance.png"><img class="size-medium wp-image-1071" src="https://www.codepedia.org/wp-content/uploads/2014/01/3-check-project-jdk-compliance-294x300.png" alt="Check project JDK compliance" width="294" height="300" srcset="https://www.codepedia.org/wp-content/uploads/2014/01/3-check-project-jdk-compliance-294x300.png 294w, https://www.codepedia.org/wp-content/uploads/2014/01/3-check-project-jdk-compliance.png 741w" sizes="(max-width: 294px) 100vw, 294px" /></a>
<p class="wp-caption-text">
Project -> Properties -> Java Compiler
</p>
</div>
the default was on 1.5, which should be no problem for Java 7…
After looking again in the console it struck me:
<div id="attachment_1072" style="width: 310px" class="wp-caption alignnone">
<a href="https://www.codepedia.org/wp-content/uploads/2014/01/4-console-output.png"><img class="size-medium wp-image-1072" src="https://www.codepedia.org/wp-content/uploads/2014/01/4-console-output-300x177.png" alt="Console output" width="300" height="177" srcset="https://www.codepedia.org/wp-content/uploads/2014/01/4-console-output-300x177.png 300w, https://www.codepedia.org/wp-content/uploads/2014/01/4-console-output-1024x604.png 1024w" sizes="(max-width: 300px) 100vw, 300px" /></a>
<p class="wp-caption-text">
Console output
</p>
</div>
…it was indeed using the older JDK (1.6) at execution time. This was caused by using an Alternate JRE (which was set to `jdk1.6.0_39`), in the setup of the **Run Configuration**:
<div id="attachment_1073" style="width: 310px" class="wp-caption alignnone">
<a href="https://www.codepedia.org/wp-content/uploads/2014/01/5-run-configuration-JRE.png"><img class="size-medium wp-image-1073" src="https://www.codepedia.org/wp-content/uploads/2014/01/5-run-configuration-JRE-300x215.png" alt="run configuration JRE" width="300" height="215" srcset="https://www.codepedia.org/wp-content/uploads/2014/01/5-run-configuration-JRE-300x215.png 300w, https://www.codepedia.org/wp-content/uploads/2014/01/5-run-configuration-JRE-1024x737.png 1024w, https://www.codepedia.org/wp-content/uploads/2014/01/5-run-configuration-JRE.png 1289w" sizes="(max-width: 300px) 100vw, 300px" /></a>
<p class="wp-caption-text">
Eclipse Menu -> Run -> Run configurations
</p>
</div>
After selecting the “Workspace default JRE (jdk1.7.0_45)” everything worked as expected.
I hope you could learn something from this as I did.
<div id="about_author" style="background-color: #e6e6e6; padding: 10px;">
<img id="author_portrait" style="float: left; margin-right: 20px;" src="https://www.codepedia.org/images/authors/amacoder.png" alt="Podcastpedia image" />
<p id="about_author_header">
<strong>Adrian Matei</strong>
</p>
<div id="author_details" style="text-align: justify;">
Creator of <a title="Podcastpedia.org, knowledge to go" href="https://github.com/CodepediaOrg/podcastpedia" target="_blank">Podcastpedia.org</a> and <a title="CodepediaOrg, share code knowledge" href="https://www.codepedia.org" target="_blank">Codepedia.org</a>, computer science engineer, husband, father, curious and passionate about science, computers, software, education, economics, social equity, philosophy - but these are just outside labels and not that important, deep inside we are all just consciousness, right?
</div>
<div id="follow_social" style="clear: both;">
<div id="social_logos">
<a class="icon-twitter" href="https://twitter.com/CodepediaOrg" target="_blank"> </a> <a class="icon-facebook" href="https://www.facebook.com/CodepediaOrg" target="_blank"> </a> <a class="icon-linkedin" href="https://www.linkedin.com/company/codepediaorg" target="_blank"> </a> <a class="icon-github" href="https://github.com/adi-matei" target="_blank"> </a>
</div>
<div class="clear">
</div>
</div>
</div>