bad class :类文件版本错误 55.0,应该是 52.0 Maven Eclipse

问题描述 投票:0回答:1

错误的类错误:我的系统没有 Java 11,它仍然指向 Java 8(在环境变量、Eclipse 构建路径、Eclipse Java 编译器级别)仍然存在编译错误类文件的版本错误 55.0,应该是 52.0 .

最近chrome升级到122版本,后来我们不得不更新selenium到4.17.0和web driver到5.6.3以使其兼容chrome 122版本。

错误:

java.lang.UnsupportedClassVersionError: testrunners/MyTestRunner has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:766)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:490)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:513)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

POM.xml:

     <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>HybridFramework1</groupId>
    <artifactId>HybridFramework1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
 
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>11</java.version>
        <junit.version>4.13.1</junit.version>
        <cucumber.version>6.9.0</cucumber.version>
        <maven.compiler.version>3.8.1</maven.compiler.version>
        <maven.surefire.version>2.22.2</maven.surefire.version>
 
    </properties>
 
    <dependencies>
 
 
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
 
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
 
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
 
    <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.18.1</version>
</dependency>
 
    <dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.6.3</version>
</dependency>
 
        <dependency>
            <groupId>tech.grasshopper</groupId>
            <artifactId>extentreports-cucumber6-adapter</artifactId>
            <version>2.8.0</version>
            <scope>test</scope>
        </dependency>
 
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
        <!--    <scope>test</scope> -->
        </dependency>
 
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>5.0.0</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.2</version>
        </dependency>
        
        <dependency>
            <groupId>com.akathist.maven.plugins.launch4j</groupId>
            <artifactId>launch4j-maven-plugin</artifactId>
            <version>1.5.1</version>
        </dependency>
 
 
 
    </dependencies>
 
    <build>
        <plugins>
 
 
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven.surefire.version}</version>
                <configuration>
                    <includes>
                        <include>**/ParallelRun.java</include>
                    </includes>
                    <parallel>methods</parallel>
                    <threadCount>4</threadCount>
                    <useUnlimitedThreads>false</useUnlimitedThreads>
                </configuration>
            </plugin>
 
            <!-- <plugin> <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>3.0.0-M3</version> <executions> <execution> <goals>
            <goal>integration-test</goal>
                </goals> <configuration>
            UNCOMMENT - To add any exclusions if required <excludes>
            <exclude>**/*IT*.java</exclude> </excludes> <includes> UNCOMMENT
            BELOW LINE
                - To execute feature files with a single runner
            <include>**/MyTestRunner.java</include>
                UNCOMMENT BELOW LINE -
            To execute feature files with multiple runners
            <include>**/*Runner.java</include>
                </includes> UNCOMMENT BELOW
            3 LINES - To execute using parallel or combination
                option
            <parallel>methods</parallel> <threadCount>4</threadCount>
            <perCoreThreadCount>true</perCoreThreadCount>
                UNCOMMENT BELOW
            3 LINES - To execute using forking or combination option
            <forkCount>2</forkCount> <reuseForks>true</reuseForks>
            <reportsDirectory>${project.build.directory}/failsafe-reports_${surefire.forkNumber}</reportsDirectory>
            </configuration> </execution> </executions> </plugin> -->
 
 
        </plugins>
    </build>
</project>


  [1]: https://i.stack.imgur.com/XA8TB.png
eclipse maven selenium-webdriver compiler-errors
1个回答
0
投票

这是版本控制错误,因为Java 8,如果没有升级选项-降级其他依赖项;顺便说一句,即使您的系统在路径中有“硬编码”jre8,您甚至无法仅为您的用户更新它,您仍然可以从 Oracle 下载所需的 JDK 并在您的项目的 IDE 设置中选择它

© www.soinside.com 2019 - 2024. All rights reserved.