我已经在Eclipse上创建了一个Maven项目,并在pom.xml文件上添加了以下依赖项:
<dependency>
<groupId>com.fasterxml</groupId>
<artifactId>jackson-xml-databind</artifactId>
<version>0.6.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.0</version>
</dependency>
然后使用以下代码检查是否可以编译依赖项:
import com.fasterxml.jackson.databind.ObjectMapper;
public class App
{
public static void main(String[] args) {
ObjectMapper mapper = new ObjectMapper();
}
}
虽然Eclipse没有显示任何错误,但是当我使用以下命令编译它时:
$ javac -sourcepath src srcmainjavaApp.java
我收到以下3个错误:
srcmainjavaApp.java:6:错误:package com.fasterxml.jackson.databind不存在进口com.fasterxml.jackson.databind.ObjectMapper;^srcmainjavaApp.java:16:错误:无法找到符号ObjectMapper mapper = new ObjectMapper();^类ObjectMapper位置:班级AppsrcmainjavaApp.java:16:错误:无法找到符号ObjectMapper mapper = new ObjectMapper();^类ObjectMapper位置:班级App
请记住,与依赖项相对应的JAR文件被安装到计算机上的maven存储库中
看起来像你的项目是基于maven的,使用maven命令编译它:CD到包含pom.xml的目录,然后运行:mvn编译