gpt4 book ai didi

java - com/fasterxml/jackson/databind/ObjectMapper 与 Maven 的 NoClassDefFoundError

转载 作者:搜寻专家 更新时间:2023-11-01 01:31:53 25 4
gpt4 key购买 nike

这是一个与 here 类似的问题,不幸的是,这个问题还没有解决。

If you want to debug the code, here is the GitHub repo.

尽管我已将相关依赖项添加到 Mave pom.xml,但我得到了 ObjectMapper 的以下 NoClassDefFoundError

Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
at demo.DemoMain.main(DemoMain.java:10)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more

这里是源代码DemoMain.java

package demo;

import com.fasterxml.jackson.databind.ObjectMapper;

public class DemoMain {
public static void main(String[] args) {
System.out.println("Start");
ObjectMapper mapper = new ObjectMapper();
System.out.println("End");
}
}

这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>Demo</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.3</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>demo.DemoMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

我编译并运行应用程序

mvn clean install
java -jar target/Demo-1.0-SNAPSHOT.jar

最佳答案

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.8.5</version>
</dependency>

关于java - com/fasterxml/jackson/databind/ObjectMapper 与 Maven 的 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43826718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com