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

Maven无法导入Jackson库,编译报包不存在错误求助

Maven无法导入Jackson库,编译报包不存在错误求助

嘿,我最近在做roadmap.sh上的入门后端项目——CLI任务追踪器,这是我第一次做CLI项目,本来以为没啥问题,但自从尝试引入Jackson JSON库后就彻底卡壳了。项目在没加这个库之前运行完全正常,但现在每次编译都弹出一堆找不到包的错误:

error: package com.fasterxml.jackson.core does not exist
error: package com.fasterxml.jackson.annotations does not exist
error: package com.fasterxml.jackson.databind does not exist

我跟着教程用Maven来管理依赖,把Jackson的三个核心包都加到了pom.xml里,但Maven好像就是没法把这些库导入到项目里。我已经折腾了两周,翻了五十多篇帖子和各种没用的安装指南,还是没解决问题。

先给大家看看我的pom.xml内容:

<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <dependencies>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>2.18.2</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>2.18.2</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.18.2</version>
    </dependency>
  </dependencies>
  <groupId>TaskTracker.maven.org</groupId>
  <artifactId>TaskTracker</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>TaskTracker</name>
</project>

我当前用的是Eclipse,JDK版本是22,不太清楚classpath和模块的区别,但应该是用classpath的模式。

我已经试过的方法有:

  • 切换为Maven项目
  • 从头创建项目3次
  • 修改pom.xml(换版本、调整依赖内容)
  • 添加额外依赖
  • 手动把jar包导入到classpath
  • 创建module-info文件,之后又删掉了

另外,我运行mvn clean package时还遇到了新的错误,日志如下:

[INFO] Scanning for projects...
[INFO]
[INFO] -----------------&lt; TaskTracker.maven.org:TaskTracker &gt;------------------
[INFO] Building TaskTracker 0.0.1-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- clean:3.2.0:clean (default-clean) @ TaskTracker ---
[INFO] Deleting C:\Users\Dante-PC\Documents\JavaProjects\TaskTracker\target
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ TaskTracker ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource from src\main\resources to target\classes
[INFO]
[INFO] --- compiler:3.13.0:compile (default-compile) @ TaskTracker ---
[INFO] Recompiling the module because of changed source code.
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 3 source files with javac [debug target 1.8] to target\classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING] bootstrap class path is not set in conjunction with -source 8
  not setting the bootstrap class path may lead to class files that cannot run on JDK 8
    --release 8 is recommended instead of -source 8 -target 1.8 because it sets the bootstrap class path automatically
[WARNING] source value 8 is obsolete and will be removed in a future release
[WARNING] target value 8 is obsolete and will be removed in a future release
[WARNING] To suppress warnings about obsolete options, use -Xlint:-options.
[INFO] 4 warnings
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/Dante-PC/Documents/JavaProjects/TaskTracker/src/main/java/TaskTracker.java:[95,36] text blocks are not supported in -source 8
  (use -source 15 or higher to enable text blocks)
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.843 s
[INFO] Finished at: 2025-02-23T10:40:02-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project TaskTracker: Compilation failure
[ERROR] /C:/Users/Dante-PC/Documents/JavaProjects/TaskTracker/src/main/java/TaskTracker.java:[95,36] text blocks are not supported in -source 8
[ERROR]   (use -source 15 or higher to enable text blocks)
[ERROR]
[ERROR] -&gt; [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 

实在不知道该从哪下手了,有没有大佬能给点建议?

备注:内容来源于stack exchange,提问作者Dante Ariel Gatica Altamirano

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 11:14:52