<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: NoClassDefFoundError: net/sf/json/JSONObject in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173778#M136041</link>
    <description>&lt;P&gt;Absolutely correct! If you were to add any jars to lib/ it would be only the Apache Ivy JAR so you could use the @Grab annotation as described here: &lt;A href="http://funnifi.blogspot.com/2016/05/using-groovy-grab-with-executescript.html" target="_blank"&gt;http://funnifi.blogspot.com/2016/05/using-groovy-grab-with-executescript.html&lt;/A&gt;. Otherwise, use Bryan's suggestion for best results.&lt;/P&gt;</description>
    <pubDate>Sun, 14 Aug 2016 01:58:38 GMT</pubDate>
    <dc:creator>mburgess</dc:creator>
    <dc:date>2016-08-14T01:58:38Z</dc:date>
    <item>
      <title>NoClassDefFoundError: net/sf/json/JSONObject</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173774#M136037</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I've been trying to run an update processor script for nifi using Groovy. I am reusing the below script from Github.&lt;/P&gt;&lt;PRE&gt;import groovy.json.JsonBuilder
import groovyx.net.http.RESTClient

import static groovy.json.JsonOutput.prettyPrint
import static groovy.json.JsonOutput.toJson
import static groovyx.net.http.ContentType.JSON

//@Grab(group='org.codehaus.groovy.modules.http-builder',
     //   module='http-builder',
        //version='0.7.1')

def processorName = 'Save File'
def host = 'localhost'
//def host = 'agrande-nifi-1'
def port = 9090
def nifi = new RESTClient("http://$host:$port/nifi-api/")

println 'Looking up a component to update...'
def resp = nifi.get(
    path: 'controller/search-results',
    query: [q: processorName]
)
assert resp.status == 200
assert resp.data.searchResultsDTO.processorResults.size() == 1
// println prettyPrint(toJson(resp.data))

def processorId = resp.data.searchResultsDTO.processorResults[0].id
def processGroup= resp.data.searchResultsDTO.processorResults[0].groupId
println "Found the component, id/group:  $processorId/$processGroup"

println 'Preparing to update the flow state...'
resp = nifi.get(path: 'controller/revision')
assert resp.status == 200

// stop the processor before we can update it
println 'Stopping the processor to apply changes...'
def builder = new JsonBuilder()
builder {
    revision {
        clientId 'my awesome script'
        version resp.data.revision.version
    }
    processor {
        id "$processorId"
        state "STOPPED"
    }
}
resp = nifi.put(
    path: "controller/process-groups/$processGroup/processors/$processorId",
    body: builder.toPrettyString(),
    requestContentType: JSON
)
assert resp.status == 200
// create a partial JSON update doc
// TIP: don't name variables same as json keys, simplifies your life
builder {
    revision {
        clientId 'my awesome script'
        version resp.data.revision.version
    }
    processor {
        id "$processorId"
        config {
            properties {
                'Directory' '/tmp/staging'
                'Create Missing Directories' 'true'
            }
        }
    }
}

println "Updating processor...\n${builder.toPrettyString()}"

resp = nifi.put(
    path: "controller/process-groups/$processGroup/processors/$processorId",
    body: builder.toPrettyString(),
    requestContentType: JSON
)
assert resp.status == 200

println "Updated ok."
// println "Got this response back:"
// print prettyPrint(toJson(resp.data))
println 'Bringing the updated processor back online...'
builder {
    revision {
        clientId 'my awesome script'
        version resp.data.revision.version
    }
    processor {
        id "$processorId"
        state "RUNNING"
    }
}
resp = nifi.put(
    path: "controller/process-groups/$processGroup/processors/$processorId",
    body: builder.toPrettyString(),
    requestContentType: JSON
)
assert resp.status == 200

println 'Ok'&lt;/PRE&gt;&lt;P&gt;Except i have commented out the Maven dependency part using &lt;STRONG&gt;@Grab &lt;/STRONG&gt; part. I have directly download the &lt;STRONG&gt;http-builder-0.6.jar&lt;/STRONG&gt;&lt;STRONG&gt; &lt;/STRONG&gt; and put it into groovy designated Library directory to have the classes available. I have also downloaded and put the &lt;STRONG&gt;json-lib.jar&lt;/STRONG&gt; in the library. &lt;/P&gt;&lt;P&gt;I'm still getting below exception at run-time&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;groovyx.net.http.ContentType.JSON&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Caught:
java.lang.NoClassDefFoundError: net/sf/json/JSONObject&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;java.lang.NoClassDefFoundError:
net/sf/json/JSONObject&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;  at
groovyx.net.http.HTTPBuilder.&amp;lt;init&amp;gt;(HTTPBuilder.java:175)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;  at
groovyx.net.http.HTTPBuilder.&amp;lt;init&amp;gt;(HTTPBuilder.java:194)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;  at
groovyx.net.http.RESTClient.&amp;lt;init&amp;gt;(RESTClient.java:79)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;  at
Groovy_Sample.run(Groovy_Sample.groovy:13)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Caused by:
java.lang.ClassNotFoundException: net.sf.json.JSONObject&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I cant trace out whats possibly going wrong, even with the jars in library, I have read that setting the right version in Maven dependency might help, but I dont use it, is there no way to do it without Maven? OR am i missing something with the Jar and libraries. &lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2016 11:58:51 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173774#M136037</guid>
      <dc:creator>suman_gupta2</dc:creator>
      <dc:date>2016-08-12T11:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: NoClassDefFoundError: net/sf/json/JSONObject</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173775#M136038</link>
      <description>&lt;P&gt;Can you please try putting your jars under &amp;lt;nifi_home&amp;gt;/lib dir.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2016 21:00:55 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173775#M136038</guid>
      <dc:creator>mpandit</dc:creator>
      <dc:date>2016-08-12T21:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: NoClassDefFoundError: net/sf/json/JSONObject</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173776#M136039</link>
      <description>&lt;A rel="user" href="https://community.cloudera.com/users/12395/sumangupta2.html" nodeid="12395"&gt;@sam coderunner&lt;/A&gt;&lt;P&gt; According to following link, json-lib requires additional dependencies in your class path including groovy-all.jar. do you have these depndencies in your classpath?&lt;/P&gt;&lt;P&gt;&lt;A href="http://json-lib.sourceforge.net/dependencies.html" target="_blank"&gt;http://json-lib.sourceforge.net/dependencies.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Aug 2016 12:14:22 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173776#M136039</guid>
      <dc:creator>mqureshi</dc:creator>
      <dc:date>2016-08-13T12:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: NoClassDefFoundError: net/sf/json/JSONObject</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173777#M136040</link>
      <description>&lt;P&gt;You can provide additional dependencies to the ExecuteScript processor by using the "Module Directory" property as described here: &lt;/P&gt;&lt;P&gt;&lt;A href="http://funnifi.blogspot.com/2016/02/executescript-using-modules.html" target="_blank"&gt;http://funnifi.blogspot.com/2016/02/executescript-using-modules.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You generally shouldn't put any jars into NiFi's lib directory because that can impact all other NARs.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Aug 2016 01:14:47 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173777#M136040</guid>
      <dc:creator>bbende</dc:creator>
      <dc:date>2016-08-14T01:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: NoClassDefFoundError: net/sf/json/JSONObject</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173778#M136041</link>
      <description>&lt;P&gt;Absolutely correct! If you were to add any jars to lib/ it would be only the Apache Ivy JAR so you could use the @Grab annotation as described here: &lt;A href="http://funnifi.blogspot.com/2016/05/using-groovy-grab-with-executescript.html" target="_blank"&gt;http://funnifi.blogspot.com/2016/05/using-groovy-grab-with-executescript.html&lt;/A&gt;. Otherwise, use Bryan's suggestion for best results.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Aug 2016 01:58:38 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173778#M136041</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2016-08-14T01:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: NoClassDefFoundError: net/sf/json/JSONObject</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173779#M136042</link>
      <description>&lt;P&gt;Hi Matt,&lt;/P&gt;&lt;P&gt;thanks for your comments, I followed what you said and downloaded the Apache Ivy Jar named : "&lt;STRONG&gt;ivy-2.4.0.jar&lt;/STRONG&gt;" from
&lt;A href="http://ant.apache.org/ivy/download.cgi"&gt;http://ant.apache.org/ivy/download.cgi&lt;/A&gt; and put it under  in  &lt;STRONG&gt;$NIFI_HOME/lib&lt;/STRONG&gt; folder  and the restarted the NIFI service. As you highlighted, i should be able to use the grab annotation now.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;@Grab(group='org.codehaus.groovy.modules.http-builder',&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;     
  module='http-builder',&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;        version='0.7.1')&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;So in the script i have un-commented the @Grab part and ran it from command line with groovysh. Now i'm getting the below error after executing the script. The error is in attached file. &lt;A href="https://community.cloudera.com/legacyfs/online/attachments/6682-error.txt"&gt;error.txt&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Is some configuration still missing, i read your blog post to know that it has something to do with the Grape cache and we need to configure it correctly? I could see that there is no /grapes folder under the /groovy directory&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 18:22:56 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173779#M136042</guid>
      <dc:creator>suman_gupta2</dc:creator>
      <dc:date>2016-08-16T18:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: NoClassDefFoundError: net/sf/json/JSONObject</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173780#M136043</link>
      <description>&lt;P&gt;Do you have Groovy installed on your machine? If so try:&lt;/P&gt;&lt;P&gt;grape install org.codehaus.groovy.modules.http-builder http-builder 0.7.1&lt;/P&gt;&lt;P&gt;If that doesn't work, then the @Grab won't work either (lots of folks seem to have trouble grabbing that module). In that case you should put the &lt;A target="_blank" href="https://mvnrepository.com/artifact/org.codehaus.groovy.modules.http-builder/http-builder/0.7.1"&gt;http-builder&lt;/A&gt; JAR (and its dependencies) into some folder and use Module Directory as Bryan suggested.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 01:32:20 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173780#M136043</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2016-08-17T01:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: NoClassDefFoundError: net/sf/json/JSONObject</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173781#M136044</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/641/mburgess.html" nodeid="641"&gt;@Matt Burgess&lt;/A&gt; It worked! I tried with  grape install command from command line and it popped some messages which stated that the jars are found in library. Now i can see a &lt;STRONG&gt;.groovy/grapes&lt;/STRONG&gt; folder in documents which has the appropriate jar files! I ran the scripts thereafter and it successfully updated the processor properties as expected. I guess its now resolving the missing jar file paths on its own since the install. However I also noticed that having the @Grab part active or not doesn't matter to the code anymore. &lt;/P&gt;&lt;P&gt;Much appreciated and thanks a ton to you and Bryan for the most valuable inputs! &lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 16:33:57 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-net-sf-json-JSONObject/m-p/173781#M136044</guid>
      <dc:creator>suman_gupta2</dc:creator>
      <dc:date>2016-08-17T16:33:57Z</dc:date>
    </item>
  </channel>
</rss>

