You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行Appium测试遇jdk.proxy2.$Proxy40.proxyClassLookup()方法缺失异常求助

解决方案:jdk.proxy2.$Proxy40.proxyClassLookup() 方法不存在异常

这个异常的核心原因是:jdk.proxy2是JDK9及以上版本才有的代理包,而你的运行环境是JDK8,却生成了仅高版本JDK兼容的代理类。结合你的环境配置,给出几个可行的解决方向:

1. 强制Maven Surefire用JDK8环境运行测试

Surefire插件可能在fork测试进程时,默认使用了系统中安装的高版本JDK(即使项目编译用JDK8),导致生成了jdk.proxy2开头的代理类,最终在JDK8环境运行时抛出异常。

在pom.xml的surefire插件配置里,明确指定JDK8的路径并强制fork:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M5</version>
    <configuration>
        <forkCount>1</forkCount>
        <reuseForks>false</reuseForks>
        <!-- 替换成你本地JDK8的绝对路径,比如Windows下的C:\Program Files\Java\jdk1.8.0_301 -->
        <javaHome>/usr/lib/jvm/java-8-openjdk-amd64</javaHome>
        <systemPropertyVariables>
            <test>${test}</test>
        </systemPropertyVariables>
    </configuration>
</plugin>

2. 排除高版本ASM依赖,引入JDK8兼容的ASM库

代理类生成依赖ASM库,TestNG或Appium的依赖中可能引入了针对JDK9+的高版本ASM(比如ASM 8.x),导致生成的代理类使用了JDK9+的特性。

首先执行mvn dependency:tree查看依赖树,找到asm/asm-commons的高版本依赖,然后在TestNG或Appium的依赖中排除它们,再手动引入兼容JDK8的ASM 7.1版本:

<!-- 排除TestNG中的高版本ASM -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.3.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm-commons</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<!-- 引入JDK8兼容的ASM版本 -->
<dependency>
    <groupId>org.ow2.asm</groupId>
    <artifactId>asm</artifactId>
    <version>7.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.ow2.asm</groupId>
    <artifactId>asm-commons</artifactId>
    <version>7.1</version>
    <scope>test</scope>
</dependency>

3. 降级Surefire到稳定兼容版

你当前用的3.0.0-M5是里程碑版本,存在兼容性问题的概率较高。可以降级到针对JDK8优化的稳定版,比如2.22.2,同时配合上述fork配置:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.2</version>
    <configuration>
        <forkCount>1</forkCount>
        <reuseForks>false</reuseForks>
        <javaHome>${java.home}</javaHome>
    </configuration>
</plugin>

验证步骤

修改配置后,先执行mvn clean test -Dtest=ms.testProject.tests.package1.testClass#test1,同时检查控制台输出的JDK版本信息,确保测试进程确实用的是JDK8。

内容的提问来源于stack exchange,提问作者nef

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 11:13:09