I have one problem which I really don't know what to do. I have a Hadoop sequence file containing the links of the webpage. Each entry of the Hadoop sequence file, the key will be the URL of one webpage and the value would be its attributes and its links. The value actually is a Json format. I want to read all of the sequence file and pass the value to jackson parser to get the links, however it always failed. Here is my code:
Configuration conf = new Configuration();
Path seqFilePath = new Path("metadata-00000");
SequenceFile.Reader reader = new SequenceFile.Reader(conf,
Reader.file(seqFilePath));
Writable key = (Writable)ReflectionUtils.newInstance(reader.getKeyClass(), conf);
Writable value = (Writable)ReflectionUtils.newInstance(reader.getValueClass(), conf);
int count = 0;
while(reader.next(key, value)) {
System.out.println(value.toString());
JsonParser jsonParser = new JsonFactory().createJsonParser(value.toString());
while(jsonParser.nextToken() != JsonToken.END_OBJECT) {
String name = jsonParser.getCurrentName();
if(name.equals("server_ip")) {
System.out.println(jsonParser.getValueAsString());
}
if(name.equals("links")) {
while(jsonParser.nextToken() != JsonToken.END_ARRAY) {
String attribute = jsonParser.getCurrentName();
if(attribute.equals("href")) {
System.out.println(jsonParser.getValueAsString());
}
}
}
}
long position = reader.getPosition();
System.out.println(position);
count++;
if(count == 5) {
break;
}
}
The file "metadata-00000" is the original Hadoop sequence file. As you can see, the value is actually in json format and I want to analyze it in Jackson parser. However, this line always failed:
JsonParser jsonParser = new JsonFactory().createJsonParser(value.toString());
the exception is:
Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonFactory
at WebParser.ParserTest.main(ParserTest.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.JsonFactory
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:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 6 more
So how should I deal with it? How can I transfer the Writable value to json parser? Thanks!