gpt4 book ai didi

java - json 模式 validator NoClassDefFoundError : com/google/common/io/Closer

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:23:07 27 4
gpt4 key购买 nike

解决方案:添加guava依赖:

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>

我在这里尝试使用 json-schema-validator:https://github.com/fge/json-schema-validator .

我正在使用以下 Maven 依赖项:

<dependency>
<groupId>com.github.fge</groupId>
<artifactId>json-schema-validator</artifactId>
<version>2.2.5</version>
</dependency>

这是我正在尝试的类(class):

import java.io.IOException;
import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jackson.JsonLoader;

public class JsonSchemaTest {
public static void main(String[] args) throws IOException {
JsonNode jsonNode = JsonLoader.fromString("{\"a\":1}");
}
}

这是我收到的错误:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/io/Closer
at com.github.fge.jackson.JsonNodeReader.fromReader(JsonNodeReader.java:120)
at com.github.fge.jackson.JsonLoader.fromReader(JsonLoader.java:179)
at com.github.fge.jackson.JsonLoader.fromString(JsonLoader.java:192)
at com.cisco.webex.squared.flume.JsonSchemaTest.main(JsonSchemaTest.java:10)
Caused by: java.lang.ClassNotFoundException: com.google.common.io.Closer
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 4 more

--- 编辑:

如果我将我的 maven 版本更改为 2.1.7,我可以执行 JsonNode jsonNode = JsonLoader.fromString("{\"a\":1}"); 但如果没有相同的 java.lang.NoClassDefFoundError: com/google/common/io/Closer 错误,我无法在此处创建工厂:

import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jackson.JsonLoader;
import com.github.fge.jsonschema.exceptions.ProcessingException;
import com.github.fge.jsonschema.main.JsonSchema;
import com.github.fge.jsonschema.main.JsonSchemaFactory;
import com.github.fge.jsonschema.report.ProcessingReport;

public final class JsonSchemaTest {
public static void main(final String[] args) throws IOException, ProcessingException {
//JsonNode data = JsonLoader.fromString("{\"a\":1}");
final JsonNode data = JsonLoader.fromString("{\"a\":1}");
final JsonNode fstabSchema = JsonLoader.fromString("{\"type\":\"object\", \"properties\":{\"a\":{\"type\":\"number\"}}}");

final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
final JsonSchema schema = factory.getJsonSchema(fstabSchema);

ProcessingReport report;

report = schema.validate(data);
System.out.println(report);
}
}

最佳答案

您必须在项目中导入 guava 库。

http://www.java2s.com/Code/Jar/g/Downloadguava150rc1jar.htm

关于java - json 模式 validator NoClassDefFoundError : com/google/common/io/Closer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26170074/

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