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

JAVA项目集成TDLib报错UnsatisfiedLinkError:找不到tdjni求助

java.lang.UnsatisfiedLinkError: no tdjni in java.library.path

我在Java项目中集成TDLib时,一直遇到以下错误:

java.lang.UnsatisfiedLinkError: no tdjni in java.library.path

最初我创建了Maven项目并引入依赖,pom.xml内容如下:

<modelVersion>4.0.0</modelVersion>
<groupId>telegram</groupId>
<artifactId>project</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <junit.version>5.6.0</junit.version>
  <maven-enforcer-plugin.version>3.0.0-M3</maven-enforcer-plugin.version>
  <maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version>
  <checkstyle.version>8.45.1</checkstyle.version>
  <maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
  <jacoco-maven-plugin.version>0.8.4</jacoco-maven-plugin.version>
  <maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
  <!-- JaCoCo thresholds. Increase gradually as you add tests. -->
  <jacoco.unit-tests.limit.instruction-ratio>0%</jacoco.unit-tests.limit.instruction-ratio>
  <jacoco.unit-tests.limit.branch-ratio>0%</jacoco.unit-tests.limit.branch-ratio>
  <jacoco.unit-tests.limit.class-complexity>20</jacoco.unit-tests.limit.class-complexity>
  <jacoco.unit-tests.limit.method-complexity>5</jacoco.unit-tests.limit.method-complexity>
</properties>
<dependencies>
  <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>${junit.version}</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>${junit.version}</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>ca.denisab85</groupId>
    <artifactId>tdlib</artifactId>
    <version>v1.8.8-20221107</version>
  </dependency>
</dependencies>
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-enforcer-plugin</artifactId>
      <version>${maven-enforcer-plugin.version}</version>
      <executions>
        <execution>
          <goals>
            <goal>enforce</goal>
          </goals>
          <configuration>
            <rules>
              <requireMavenVersion>
                <version>3.6.3</version>
              </requireMavenVersion>
            </rules>
            <fail>true</fail>
          </configuration>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-checkstyle-plugin</artifactId>
      <version>${maven-checkstyle-plugin.version}</version>
      <dependencies>
        <dependency>
          <groupId>com.puppycrawl.tools</groupId>
          <artifactId>checkstyle</artifactId>
          <version>${checkstyle.version}</version>
        </dependency>
        <dependency>
          <groupId>com.github.ngeor</groupId>
          <artifactId>checkstyle-rules</artifactId>
          <version>4.9.3</version>
        </dependency>
      </dependencies>
      <configuration>
        <configLocation>com/github/ngeor/checkstyle.xml</configLocation>
        <includeTestSourceDirectory>true</includeTestSourceDirectory>
        <skip>${skipTests}</skip>
      </configuration>
      <executions>
        <execution>
          <id>checkstyle</id>
          <phase>validate</phase>
          <goals>
            <goal>check</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>${maven-surefire-plugin.version}</version>
    </plugin>
    <plugin>
      <groupId>org.jacoco</groupId>
      <artifactId>jacoco-maven-plugin</artifactId>
      <version>${jacoco-maven-plugin.version}</version>
      <executions>
        <execution>
          <id>pre-unit-test</id>
          <goals>
            <goal>prepare-agent</goal>
          </goals>
        </execution>
        <execution>
          <id>post-unit-test</id>
          <phase>test</phase>
          <goals>
            <goal>report</goal>
          </goals>
        </execution>
        <execution>
          <id>check-unit-test</id>
          <phase>test</phase>
          <goals>
            <goal>check</goal>
          </goals>
          <configuration>
            <dataFile>${project.build.directory}/jacoco.exec</dataFile>
            <rules>
              <rule>
                <element>BUNDLE</element>
                <limits>
                  <limit>
                    <counter>INSTRUCTION</counter>
                    <value>COVEREDRATIO</value>
                    <minimum>${jacoco.unit-tests.limit.instruction-ratio}</minimum>
                  </limit>
                  <limit>
                    <counter>BRANCH</counter>
                    <value>COVEREDRATIO</value>
                    <minimum>${jacoco.unit-tests.limit.branch-ratio}</minimum>
                  </limit>
                </limits>
              </rule>
              <rule>
                <element>CLASS</element>
                <limits>
                  <limit>
                    <counter>COMPLEXITY</counter>
                    <value>TOTALCOUNT</value>
                    <maximum>${jacoco.unit-tests.limit.class-complexity}</maximum>
                  </limit>
                </limits>
              </rule>
              <rule>
                <element>METHOD</element>
                <limits>
                  <limit>
                    <counter>COMPLEXITY</counter>
                    <value>TOTALCOUNT</value>
                    <maximum>${jacoco.unit-tests.limit.method-complexity}</maximum>
                  </limit>
                </limits>
              </rule>
            </rules>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
<reporting>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-javadoc-plugin</artifactId>
      <version>${maven-javadoc-plugin.version}</version>
    </plugin>
  </plugins>
</reporting>
</project>

尝试上述方法无效后,我按照TDLib官方构建指南操作,运行示例代码仍出现相同错误。

之后我查阅资料得知需要指定java.library.path路径,于是执行了以下命令:

java -Djava.library.path=C:/Users/PC/td/tdlib/bin/tdjni.dll

但问题依然没有解决。我当前使用Windows系统,在Mac M1设备上也遇到同样的问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 04:13:07