# 常见问题

# 模型加载失败

java.net.UnknownHostException: resources.djl.ai

检查网络是否有问题,如果未手动指定模型路径,需要联网使用

# windows系统 Can't find dependent libraries

java.lang.UnsatisfiedLinkError: C:\Users\xxx\AppData\Local\Temp\smartjavaai-native-libs5875298554139322524\tennis.dll: Can't find dependent libraries

检查网络是否有问题,如果未手动指定模型路径,需要联网使用 一般是因为电脑依赖库缺失,需要安装依赖库,可以点击安装运行库合集 (opens new window)

# windows使用gpu报错:Can't find dependent libraries

Caused by: java.lang.UnsatisfiedLinkError: D:\Software\.djl.ai\pytorch\2.4.0-cu124-win-x86_64\torch_cuda.dll: Can't find dependent libraries

该问题通常是由于环境变量 PATH 配置不当所导致

# 解决方法:

1、删除PATH中所有已有的 CUDA 相关环境变量

2、将SmartJavaAI的CUDA缓存路径加入到PATH中 可以参考下图:

# linux系统,报错:找不到GLIBCXX_3.4.20

Caused by: java.lang.UnsatisfiedLinkError: /root/smartjavaai_cache/pytorch/2.5.1-cpu-linux-x86_64/libc10.so: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /root/smartjavaai_cache/pytorch/2.5.1-cpu-linux-x86_64/libc10.so)

报错原因:因为linux系统版本过低,需要更新系统或者安装GLIBCXX_3.4.20依赖库,常见于centos7系统,建议使用ubuntu24.04或者其他内核版本高的linux系统。

# 打包后运行jar包,报错:ModelZoo not found in classpath: ai.djl.pytorch

Exception in thread "main" java.lang.IllegalArgumentException: ModelZoo not found in classpath: ai.djl.pytorch

报错原因:由于普通打包方式会导致文件丢失

解决方法:使用maven shade插件打包,mainClass需替换为你的mainClass

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>3.5.0</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals><goal>shade</goal></goals>
          <configuration>
            <createDependencyReducedPom>false</createDependencyReducedPom>
            <transformers>
              <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
              <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <mainClass>${exec.mainClass}</mainClass>
              </transformer>
            </transformers>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

# 日志jar冲突

SmartJavaAI 项目中默认引入了 slf4j-simple 作为日志实现。如果你的项目中已经使用了其他日志框架(如 logback-classic 或 log4j 等),则可能会出现 SLF4J 绑定冲突 的错误提示

解决方案:建议在你的项目中排除 SmartJavaAI 模块中默认引入的 slf4j-simple

<exclusions>
  <exclusion>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
  </exclusion>
</exclusions>