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

运行Maven构建的JAR文件时因Zebra SDK依赖配置报错

问题根源

你用system scope配置Zebra SDK依赖时,使用了相对路径${project.basedir}/lib/ZSDK_ANDROID_API.jar,而Spring Boot Thin Jar运行时会重新解析Maven依赖树,它无法识别这种相对路径;同时Maven本身也不建议system依赖指向项目内部文件(依赖该项目的其他模块无法访问这个Jar),这两个原因导致了运行报错。

解决办法

优先选方法1,从根本上解决system依赖的问题:

方法1:把Zebra Jar安装到本地Maven仓库

在项目根目录执行这条Maven命令:

mvn install:install-file -Dfile=lib/ZSDK_ANDROID_API.jar -DgroupId=your.groupId -DartifactId=external-library -Dversion=2.9.2275 -Dpackaging=jar

然后修改POM里的依赖,删掉system和systemPath,改成普通依赖:

<dependency>
    <groupId>your.groupId</groupId>
    <artifactId>external-library</artifactId>
    <version>2.9.2275</version>
</dependency>

重新打包运行,Thin Jar就能正常解析依赖了。

方法2:打包成包含所有依赖的Fat Jar

如果不需要Thin Jar,直接打包成Fat Jar,把system依赖打包进去:
修改Spring Boot Maven插件配置:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <includeSystemScope>true</includeSystemScope>
            </configuration>
        </plugin>
    </plugins>
</build>

执行mvn clean package生成Fat Jar,运行这个Jar就不会有依赖解析问题。

方法3:给Thin Jar配置本地额外仓库

如果一定要用Thin Jar且不想安装到本地仓库,在POM里配置Thin插件的额外仓库:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot.experimental</groupId>
                    <artifactId>spring-boot-thin-layout</artifactId>
                    <version>1.1.0.RELEASE</version>
                </dependency>
            </dependencies>
            <configuration>
                <thin>
                    <extraRepositories>
                        <repository>file:${project.basedir}/lib</repository>
                    </extraRepositories>
                </thin>
            </configuration>
        </plugin>
    </plugins>
</build>

同时把依赖的scope改成compile,删掉systemPath,让Thin Jar从本地lib目录加载这个Jar。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 00:45:26