Json-schema-validator NoClassDefFoundError: com / google / common / io / Closer

Solution: Add guava dependency:

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

      


I'm trying to use the json-schema-validator here: https://github.com/fge/json-schema-validator .

I am using the following maven dependency:

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

      

Here is the class I'm trying:

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}");
    }
}

      

And here is the error I am getting:

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

      

--- Edit:

If I change my maven version to 2.1.7

, I can do JsonNode jsonNode = JsonLoader.fromString("{\"a\":1}");

, but I cannot create a factory here without the same error 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);
    }
}

      

+3


source to share


1 answer


You need to import the guava library into your project.



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

+2


source







All Articles