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

AWS Device Farm上传Java TestNG项目时dependency-jars目录缺失报错

解决AWS Device Farm上传Java TestNG测试包提示“未找到dependency-jars目录”的问题

我之前帮别人排查过类似的AWS Device Farm上传问题,你的情况大概率是打包后的zip结构不符合AWS的要求,咱们一步步来拆解问题并解决:

先明确AWS Device Farm的要求

AWS Device Farm对Java TestNG测试包的结构有严格要求:

你的测试zip包的根目录下必须直接包含:

  1. 你的测试类Jar文件(比如your-test-project.jar)
  2. dependency-jars目录,里面存放所有依赖Jar(Selenium、TestNG等)

如果dependency-jars在zip的子目录里,或者zip结构层级不对,AWS就会抛出你遇到的错误。

步骤1:检查Maven打包插件配置

你提到用了Maven打zip-with-dependencies包,大概率是插件配置没把文件放到正确的层级。以下是正确的配置示例:

配置maven-dependency-plugin(复制依赖到dependency-jars)

先确保依赖被正确复制到target/dependency-jars:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>3.6.0</version>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/dependency-jars</outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
        </execution>
    </executions>
</plugin>

配置maven-assembly-plugin(生成符合要求的zip)

添加assembly插件,并指定自定义的打包描述文件:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.6.0</version>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <descriptors>
                    <descriptor>src/main/assembly/assembly.xml</descriptor>
                </descriptors>
                <finalName>your-test-package</finalName>
                <appendAssemblyId>false</appendAssemblyId>
            </configuration>
        </execution>
    </executions>
</plugin>

然后在src/main/assembly/assembly.xml中定义打包结构,确保文件都在zip根目录:

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
    <id>zip-with-dependencies</id>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <!-- 把测试Jar放到zip根目录 -->
        <fileSet>
            <directory>${project.build.directory}</directory>
            <includes>
                <include>${project.build.finalName}.jar</include>
            </includes>
            <outputDirectory>/</outputDirectory>
        </fileSet>
        <!-- 把dependency-jars目录放到zip根目录 -->
        <fileSet>
            <directory>${project.build.directory}/dependency-jars</directory>
            <outputDirectory>/dependency-jars</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

步骤2:验证打包后的Zip结构

运行mvn clean package后,找到生成的zip文件,用以下命令查看结构:

unzip -l your-test-package.zip

正确的输出应该是这样的(核心是文件在根目录):

Archive:  your-test-package.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
    12345  2024-05-20 10:00   your-test-project.jar
        0  2024-05-20 10:00   dependency-jars/
   678900  2024-05-20 10:00   dependency-jars/selenium-java-4.19.0.jar
   456789  2024-05-20 10:00   dependency-jars/testng-7.8.0.jar
   ...其他依赖Jar...
---------                     -------
  1234567                     total

如果看到target/your-test-project.jar这种路径,说明配置有问题,需要调整outputDirectory为/。

步骤3:排查常见错误点

  • 错误1:打包时包含了整个target目录:这会导致AWS找不到根目录的dependency-jars,检查assembly配置里的outputDirectory是否为/。
  • 错误2:dependency-jars目录为空:确认maven-dependency-plugin是否在package阶段执行了copy-dependencies目标,或者检查本地target/dependency-jars是否真的有Jar。
  • 错误3:Zip包嵌套:如果你的zip里包含了自身(比如your-test-package.zip在zip内部),检查assembly的includes,不要包含*.zip文件。

步骤4:手动打包验证(快速排查)

如果还是有问题,手动构建符合要求的zip包测试:

  1. 运行mvn clean package生成测试Jar和dependency-jars目录。
  2. 进入target目录:cd target。
  3. 执行打包命令:zip -r ../test-package.zip your-test-project.jar dependency-jars/。
  4. 上传这个手动生成的test-package.zip到AWS Device Farm,看是否报错。

如果手动打包的能成功,说明是Maven插件配置的问题,再回头调整插件参数即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 09:32:40