java.lang.NoClassDefFoundError: com/google/common/io/Closer

1,663 views
Skip to first unread message

Matthew Moisen

unread,
Oct 2, 2014, 6:20:03 PM10/2/14
to json-schem...@googlegroups.com
Hi there,

I posted this same question on stackoverflow here before I thought of the google group, and apologize for the cross post.

I'm using the following maven dependency:


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


This is the class I made:


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



which fails with:


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

It also fails with the fromResource or fromFile methods.

If I change the maven version to 2.1.7, I can create the JsonNode instance from the JsonLoader's fromString method, but I cannot instantiate the JsonSchemaFactory without getting the same NoClassDefFoundError for that line.



import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jackson.JsonLoader;
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
import com.github.fge.jsonschema.core.report.ProcessingReport;
import com.github.fge.jsonschema.main.JsonSchema;
import com.github.fge.jsonschema.main.JsonSchemaFactory;
public final class JsonSchemaTest {
   
public static void main(final String[] args) throws IOException, ProcessingException {
   
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);
 
}
}

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:14)
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

Any ideas on what I have wrong?

Thank you,

Matthew


Francis Galiegue

unread,
Oct 15, 2014, 8:10:17 PM10/15/14
to Matthew Moisen, json-schem...@googlegroups.com
On Fri, Oct 3, 2014 at 12:20 AM, Matthew Moisen <mkmo...@gmail.com> wrote:
> Hi there,
>
> I posted this same question on stackoverflow here before I thought of the
> google group, and apologize for the cross post.
>
> I'm using the following maven dependency:
>
>
> <dependency>
> <groupId>com.github.fge</groupId>
> <artifactId>json-schema-validator</artifactId>
> <version>2.2.5</version>
> </dependency>
>
[...]

Complementing the SO answer: it looks like you use another library in
your project which uses a version of Guava less than 14.0 (the Closer
class appeared in 14.0). The best here would be to find the culprit
and exclude its Guava dependency so that json-schema-validator's one
is used instead.

Regards,
--
Francis Galiegue, fgal...@gmail.com, https://github.com/fge
JSON Schema in Java: http://json-schema-validator.herokuapp.com
Parsers in pure Java: https://github.com/parboiled1/grappa (redde
Caesaris: https://github.com/sirthias)
Reply all
Reply to author
Forward
0 new messages