0

I am trying to run my Maven project using Java JDK 1.7

Whenever I run my project (as a Maven project) (created under Java JDK 1.7) I get an error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/google/common/collect/ImmutableSet : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:425)
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
    at com.google.inject.internal.Errors.<clinit>(Errors.java:105)
    at com.google.inject.internal.InternalInjectorCreator.<init>(InternalInjectorCreator.java:61)
    at com.google.inject.Guice.createInjector(Guice.java:87)
    at com.google.inject.Guice.createInjector(Guice.java:69)
    at com.google.inject.Guice.createInjector(Guice.java:59)
    at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:481)
    at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:206)
    at org.apache.maven.cli.MavenCli.container(MavenCli.java:636)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:282)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)

Note that it is not user generated files which are out of date.

POM File

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>EndUsersServ</groupId>
  <artifactId>EndUsersService</artifactId>
  <version>0.0.1-SNAPSHOT</version>

    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>7</maven.compiler.source>
    <maven.compiler.target>7</maven.compiler.target>
  </properties>

  <dependencies>
      <!-- https://mvnrepository.com/artifact/com.sun.xml.ws/jaxws-rt -->
      <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>2.2.6</version>
      </dependency>
      <dependency>
        <groupId>com.sun.org.apache.xml.internal</groupId>
        <artifactId>resolver</artifactId>
        <version>20050927</version>
      </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.3</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>
    
</project>

I believe one or more of the maven plugins are for version 8 of Java but I am not sure which, and even if they the plugins are featured in the pom file. Do I need to completely reinstall my IDE?

Any help appreciated.

Project Facets

enter image description here

Lyra Orwell
  • 1,048
  • 4
  • 17
  • 46
  • Are you sure you still want to use Java 7? The error means that some dependency or some plugin requires Java 8. – J Fabian Meier Mar 24 '21 at 15:09
  • Does this answer your question? [Unsupported major.minor version 52.0](https://stackoverflow.com/questions/22489398/unsupported-major-minor-version-52-0) – Eritrean Mar 24 '21 at 15:10
  • Which Maven version do you use? Looks like the version that you use, doesn't support Java 7 anymore. – dunni Mar 24 '21 at 15:10
  • 1
    @dunni EMBEDDED 3.63/1.16.0.20210129-0849, WORKSPACE NOT AVAILABLE [3.0,) – Lyra Orwell Mar 24 '21 at 15:15
  • So you use the embedded Maven runtime in Eclipse, not on the command line? In that case, the minimum version of Eclipse is what counts, and i guess they already increased it to Java 8 (note, that this only refers to the runtime version, you can still run Eclipse with Java 8 and develop against JDK 7) – dunni Mar 24 '21 at 15:22
  • So I need to install a downgraded version of eclipse? If so, which version would you recommend? A download link would be useful @dunni – Lyra Orwell Mar 24 '21 at 15:25
  • No, as i said just run Eclipse with a higher Java version and use JDK 7 within your project settings as target JDK. – dunni Mar 24 '21 at 15:30
  • And you should really think about updating your Java. Java 7 is really old, and it becomes harder and harder to work with this. – J Fabian Meier Mar 24 '21 at 15:33
  • Just set your JAVA_HOME on Java 7 and build your project on plain command line. I suppose this will work. – khmarbaise Mar 24 '21 at 16:17

2 Answers2

1

I ran into a similar issue, i was using a debug configuration to compile using Java 1.7. After updating Eclipse from veersion 4.17 to version 4.21, the build stopped working with a similar error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/google/common/collect/ImmutableSet : Unsupported major.minor version 52.0

@dunni comment helped, it seems like the newest version of Eclipse embeds a new version of Maven 3.8.1 which seem to break the build. In my case, I just had to revert and install Maven locally (v3.5.3), then in Preferences > Maven > Installation > Add, use my local maven version, and the build succeeds

fnicollet
  • 151
  • 2
  • 4
0

I believe, the value should be

<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>

Running through Eclipse IDE then java 7 should be selected under Java Build Path and Java Compiler

Dina
  • 41
  • 3