- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Could not initialize class net.sf.json.JsonConfig
- Labels:
-
Apache NiFi
Created on ‎02-03-2017 03:57 PM - edited ‎08-18-2019 05:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My flow transforms data in JSON format to XML format using a Groovy script in ExecuteScript processor. The script imports net.sf.json.JSON, net.sf.json.JSONSerializer and net.sf.json.xml.XMLSerializer. I included all the jars below but I get an error, "Failed to process session due to java.lang.NoClassDefFoundError:Could not initialize class net.sf.json.JsonConfig". I tried with different versions of the jar but an error still persists. Please suggest what's going wrong.
Thanks.
Created on ‎02-03-2017 07:55 PM - edited ‎08-18-2019 05:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was able to get such a script working with those json-lib classes. I had different versions of some of those libraries though, your issue might be from using commons-collections-3.2.2 instead of 3.2.1.
I started with the dependencies (and versions) listed here, and only downloaded what I needed to get things compiling:
I set the Module Directory property to the folder containing all the JARs (versus an entry for each JAR):
/Users/mburgess/Downloads/json-lib
Here is the sample script I used (it's not pretty but compiles and runs):
import net.sf.json.* import net.sf.json.xml.* class POGO { String a List<String> b Map<String, Integer> c } def js = new JSONSerializer() def xs = new XMLSerializer() def flowFile = session.get() if(!flowFile) return def p = new POGO(a: "Hello", b: ["I", "am", "a", "list"], c: ['k1':1, 'k2':2]) def j = js.toJSON(p) def x = xs.write(j) flowFile = session.putAttribute(flowFile, 'new.value', x) session.transfer(flowFile, REL_SUCCESS)
This ignores the incoming flow file content and creates an Object which is transformed to JSON then XML (I wanted to exercise the toJSON() and write() methods), then puts the XML in an attribute (to make the example easier) and sends the flow file on.
Created ‎02-03-2017 04:05 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hey @spdvnz, any chance you could attach the whole stack trace? that is probably the class you're trying to initialize but it may have other dependencies
Created ‎02-03-2017 07:01 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, I cannot copy the log but I see the below error message. Nothing else.
"failed to process session due to java.lang.NoClassDefFoundError: org/apache/commons/collections/map/ListOrderedMap: java lang.NoClassFoundError: org/apache/commons/collections/map/ListOrderedMap" .
Created on ‎02-03-2017 07:55 PM - edited ‎08-18-2019 05:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was able to get such a script working with those json-lib classes. I had different versions of some of those libraries though, your issue might be from using commons-collections-3.2.2 instead of 3.2.1.
I started with the dependencies (and versions) listed here, and only downloaded what I needed to get things compiling:
I set the Module Directory property to the folder containing all the JARs (versus an entry for each JAR):
/Users/mburgess/Downloads/json-lib
Here is the sample script I used (it's not pretty but compiles and runs):
import net.sf.json.* import net.sf.json.xml.* class POGO { String a List<String> b Map<String, Integer> c } def js = new JSONSerializer() def xs = new XMLSerializer() def flowFile = session.get() if(!flowFile) return def p = new POGO(a: "Hello", b: ["I", "am", "a", "list"], c: ['k1':1, 'k2':2]) def j = js.toJSON(p) def x = xs.write(j) flowFile = session.putAttribute(flowFile, 'new.value', x) session.transfer(flowFile, REL_SUCCESS)
This ignores the incoming flow file content and creates an Object which is transformed to JSON then XML (I wanted to exercise the toJSON() and write() methods), then puts the XML in an attribute (to make the example easier) and sends the flow file on.
Created ‎02-06-2017 02:05 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Using commons-collections-3.2.1 solved the issue.Thanks, @Matt Burgess.
