<?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: Processor to run java code / jar file in apache nifi in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Processor-to-run-java-code-jar-file-in-apache-nifi/m-p/110281#M50717</link>
    <description>&lt;P&gt;Yes , I figured out how to run a jar in nifi using&lt;STRONG&gt; ExectureStreamCommand&lt;/STRONG&gt;&lt;STRONG&gt; processor&lt;/STRONG&gt;. &lt;/P&gt;&lt;P&gt;I am having a piece of java code , along with a jar file , by creating manifest file . I created another Master Jar file , which need to be run in nifi environment to get data. 

refer :- 
&lt;A href="http://stackoverflow.com/questions/8890747/creating-a-jar-file-which-contains-other-library-files" target="_blank" rel="nofollow noopener noreferrer"&gt;http://stackoverflow.com/questions/8890747/creating-a-jar-file-which-contains-other-library-files&lt;/A&gt;

&lt;A href="http://stackoverflow.com/questions/1082580/how-to-build-jars-from-intellij-properly" target="_blank" rel="nofollow noopener noreferrer"&gt;http://stackoverflow.com/questions/1082580/how-to-build-jars-from-intellij-properly&lt;/A&gt;

Now once we have our JAR ready , we just need to give java -jar &amp;lt;jarfilename&amp;gt;.jar conventionally .

In NIFI , we need to use ExectureStreamCommand processor .

to trigger the action , step 1) create a GenerateFlowFile 
2) In ExectureStreamCommand processor , update the properties as follows. ( here my jar name is engagement_3.jar) and we all know that the command to run java jar is&lt;STRONG&gt; &lt;/STRONG&gt;&lt;STRONG&gt;java -jar &amp;lt;jarfilename&amp;gt;.jar&lt;/STRONG&gt; but we need to &lt;STRONG&gt;omit "java"&lt;/STRONG&gt; and give rest of command , but the  delimiter is &lt;STRONG&gt;";" . 

&lt;/STRONG&gt;So the command is -jar;engagement_3.jar or -jar;&amp;lt;jarfilename&amp;gt;.jar 

In &lt;STRONG&gt;COMMAND PATH, &lt;/STRONG&gt;specify the  system environment path  , &lt;STRONG&gt;&amp;lt;JAVA_HOME&amp;gt;\bin\java&lt;/STRONG&gt;  BUT NOT  &lt;STRONG&gt;&amp;lt;JAVA_HOME&amp;gt;\bin\java.exe.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Working directory &lt;/STRONG&gt;is the location where your jar is hosted in local. &lt;/P&gt;&lt;P&gt;Rest of the properties within &lt;STRONG&gt;ExectureStreamCommand processor &lt;/STRONG&gt;are as follows. &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11134-mallesh.png" style="width: 1134px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/23321i9050C7A5C23706EB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11134-mallesh.png" alt="11134-mallesh.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;

&lt;/P&gt;</description>
    <pubDate>Mon, 19 Aug 2019 11:27:58 GMT</pubDate>
    <dc:creator>pavankumar_jall</dc:creator>
    <dc:date>2019-08-19T11:27:58Z</dc:date>
    <item>
      <title>Processor to run java code / jar file in apache nifi</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Processor-to-run-java-code-jar-file-in-apache-nifi/m-p/110278#M50714</link>
      <description>&lt;P&gt;Greetings Community , &lt;/P&gt;&lt;P&gt;I am aware of executeScript processor and InvokeScriptedProcessor where we can run python , ruby and groovy type code but I am looking for a processor where I can run java code with additional functionality to add external jars as well. &lt;/P&gt;&lt;P&gt;I found that ExecuteStreamCommand processor can be used but did not find any examples or ways to run java using that. &lt;/P&gt;&lt;P&gt;Can anyone direct me to examples / templates where a java code or jar is executed . &lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 04:25:01 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Processor-to-run-java-code-jar-file-in-apache-nifi/m-p/110278#M50714</guid>
      <dc:creator>pavankumar_jall</dc:creator>
      <dc:date>2017-01-04T04:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: Processor to run java code / jar file in apache nifi</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Processor-to-run-java-code-jar-file-in-apache-nifi/m-p/110279#M50715</link>
      <description>&lt;P&gt;For Java you need to build a custom processor and package it in a NAR. There is a Maven archetype to generate the proper project structure: &lt;A href="https://cwiki.apache.org/confluence/display/NIFI/Maven+Projects+for+Extensions" target="_blank"&gt;https://cwiki.apache.org/confluence/display/NIFI/Maven+Projects+for+Extensions&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The JARs you need would be dependencies of your processors project listed in the pom.xml&lt;/P&gt;&lt;P&gt;Then you deploy the NAR file to the lib directory of NiFi and restart.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 04:41:42 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Processor-to-run-java-code-jar-file-in-apache-nifi/m-p/110279#M50715</guid>
      <dc:creator>bbende</dc:creator>
      <dc:date>2017-01-04T04:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: Processor to run java code / jar file in apache nifi</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Processor-to-run-java-code-jar-file-in-apache-nifi/m-p/110280#M50716</link>
      <description>&lt;P&gt;Groovy syntax is very similar to Java, and using the Module Directory property of ExecuteScript or InvokeScriptedProcessor, you could include your Java code / JARs and use Groovy only to pass on data/objects to your Java code (i.e. you wouldn't need to write everything in Groovy, just enough to call your Java class(es)).&lt;/P&gt;&lt;P&gt;ExecuteStreamCommand is akin to calling something from the command line, so if you can run your code from the command line using the "java" program, you can do the same from ExecuteStreamCommand.&lt;/P&gt;&lt;P&gt;If you can describe your code/project and its entry points, I can help get you going with ExecuteScript and Groovy if you like.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 22:02:07 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Processor-to-run-java-code-jar-file-in-apache-nifi/m-p/110280#M50716</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2017-01-04T22:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: Processor to run java code / jar file in apache nifi</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Processor-to-run-java-code-jar-file-in-apache-nifi/m-p/110281#M50717</link>
      <description>&lt;P&gt;Yes , I figured out how to run a jar in nifi using&lt;STRONG&gt; ExectureStreamCommand&lt;/STRONG&gt;&lt;STRONG&gt; processor&lt;/STRONG&gt;. &lt;/P&gt;&lt;P&gt;I am having a piece of java code , along with a jar file , by creating manifest file . I created another Master Jar file , which need to be run in nifi environment to get data. 

refer :- 
&lt;A href="http://stackoverflow.com/questions/8890747/creating-a-jar-file-which-contains-other-library-files" target="_blank" rel="nofollow noopener noreferrer"&gt;http://stackoverflow.com/questions/8890747/creating-a-jar-file-which-contains-other-library-files&lt;/A&gt;

&lt;A href="http://stackoverflow.com/questions/1082580/how-to-build-jars-from-intellij-properly" target="_blank" rel="nofollow noopener noreferrer"&gt;http://stackoverflow.com/questions/1082580/how-to-build-jars-from-intellij-properly&lt;/A&gt;

Now once we have our JAR ready , we just need to give java -jar &amp;lt;jarfilename&amp;gt;.jar conventionally .

In NIFI , we need to use ExectureStreamCommand processor .

to trigger the action , step 1) create a GenerateFlowFile 
2) In ExectureStreamCommand processor , update the properties as follows. ( here my jar name is engagement_3.jar) and we all know that the command to run java jar is&lt;STRONG&gt; &lt;/STRONG&gt;&lt;STRONG&gt;java -jar &amp;lt;jarfilename&amp;gt;.jar&lt;/STRONG&gt; but we need to &lt;STRONG&gt;omit "java"&lt;/STRONG&gt; and give rest of command , but the  delimiter is &lt;STRONG&gt;";" . 

&lt;/STRONG&gt;So the command is -jar;engagement_3.jar or -jar;&amp;lt;jarfilename&amp;gt;.jar 

In &lt;STRONG&gt;COMMAND PATH, &lt;/STRONG&gt;specify the  system environment path  , &lt;STRONG&gt;&amp;lt;JAVA_HOME&amp;gt;\bin\java&lt;/STRONG&gt;  BUT NOT  &lt;STRONG&gt;&amp;lt;JAVA_HOME&amp;gt;\bin\java.exe.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Working directory &lt;/STRONG&gt;is the location where your jar is hosted in local. &lt;/P&gt;&lt;P&gt;Rest of the properties within &lt;STRONG&gt;ExectureStreamCommand processor &lt;/STRONG&gt;are as follows. &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11134-mallesh.png" style="width: 1134px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/23321i9050C7A5C23706EB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11134-mallesh.png" alt="11134-mallesh.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;

&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 11:27:58 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Processor-to-run-java-code-jar-file-in-apache-nifi/m-p/110281#M50717</guid>
      <dc:creator>pavankumar_jall</dc:creator>
      <dc:date>2019-08-19T11:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: Processor to run java code / jar file in apache nifi</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Processor-to-run-java-code-jar-file-in-apache-nifi/m-p/110282#M50718</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/641/mburgess.html" nodeid="641"&gt;@Matt Burgess&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I'm relatively new to NiFi.&lt;/P&gt;&lt;P&gt;As of now i have parsed a hl7 file using ExtractHL7Attributes and extracted required attributes using AttributesToJSON processor. From here i want to convert it into FHIR format with the use of attributes and its values from AttributesToJSON. The attributes from AttributesToJSON will look something like this,&lt;/P&gt;&lt;P&gt; {"PID.PatientName.FamilyName":"Patient","PID.PatientName.GivenName":"Test", etc. }&lt;/P&gt;&lt;P&gt;I've a java class like to convert it into FHIR format,&lt;/P&gt;&lt;P&gt;package routines; &lt;/P&gt;&lt;P&gt;import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.Identifier;
import ca.uhn.fhir.context.FhirContext;
import org.hl7.fhir.dstu3.model.ContactPoint.ContactPointSystem;
import org.hl7.fhir.dstu3.model.ContactPoint.ContactPointUse;
import org.hl7.fhir.dstu3.model.Reference; &lt;/P&gt;&lt;P&gt;public class MapFhirPatient { &lt;/P&gt;&lt;P&gt;    public static String getFhirPatient(String firstName, String lastName, String middleName, String phoneHome, String phoneWork) &lt;/P&gt;&lt;P&gt;{ &lt;/P&gt;&lt;P&gt;   String result = ""; &lt;/P&gt;&lt;P&gt;
   try{
   Patient testPatient = new Patient(); &lt;/P&gt;&lt;P&gt;   Reference reference = new Reference(); &lt;/P&gt;&lt;P&gt;   reference.setDisplay("HealthCare Org"); &lt;/P&gt;&lt;P&gt;   testPatient.addIdentifier().setUse(Identifier.IdentifierUse.OFFICIAL).setSystem("urn:fake:mrns").setValue("800001").setAssigner(reference); &lt;/P&gt;&lt;P&gt;   testPatient.addName().setFamily(lastName).addGiven(firstName).addGiven(middleName); &lt;/P&gt;&lt;P&gt;   if(phoneHome != null)
   {
   testPatient.addTelecom().setSystem(ContactPointSystem.PHONE).setUse(ContactPointUse.HOME).setValue(phoneHome);
   } &lt;/P&gt;&lt;P&gt;   if(phoneWork != null)
   {
   testPatient.addTelecom().setSystem(ContactPointSystem.PHONE).setUse(ContactPointUse.WORK).setValue(phoneWork);
   } &lt;/P&gt;&lt;P&gt;   FhirContext context = FhirContext.forDstu3(); &lt;/P&gt;&lt;P&gt;   result = context.newJsonParser().encodeResourceToString(testPatient);&lt;/P&gt;&lt;P&gt;   } &lt;/P&gt;&lt;P&gt;   catch(Exception e){  
   result = "Error occured in mapping.";  
   } &lt;/P&gt;&lt;P&gt;
   return result; &lt;/P&gt;&lt;P&gt;    }
} &lt;/P&gt;&lt;P&gt;How can i execute this code using the Module Directory property of ExecuteScript or InvokeScriptedProcessor by passing necessary parameters. And how can i get the returned data from java class and store it in a text file. &lt;/P&gt;&lt;P&gt;similar question raised by me to format JSON data - &lt;A href="https://community.hortonworks.com/questions/138833/need-to-format-values-fromin-attributestojson-proc.html?childToView=138890#answer-138890" target="_blank"&gt;https://community.hortonworks.com/questions/138833/need-to-format-values-fromin-attributestojson-proc.html?childToView=138890#answer-138890&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The end result will look something like this, which is FHIR standard for patient details.&lt;/P&gt;&lt;PRE&gt;{"resourceType":"Patient","identifier":[{"use":"official","system":"urn:fake:mrns","value":"800001","assigner":{"display":"HealthCare Org"}}],"name":[{"family":"Patient","given":"Test12"}],"telecom":[{"system":"phone","value":"111-111-1111","use":"home"}]}&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Sep 2017 16:24:25 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Processor-to-run-java-code-jar-file-in-apache-nifi/m-p/110282#M50718</guid>
      <dc:creator>vigneswar_viyas</dc:creator>
      <dc:date>2017-09-19T16:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: Processor to run java code / jar file in apache nifi</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Processor-to-run-java-code-jar-file-in-apache-nifi/m-p/110283#M50719</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;grovy code below to get flow file:-&lt;/P&gt;&lt;PRE&gt;

attrMap = ['myAttr1': '1', 'myAttr2': Integer.toString(2)]
flowFile = session.get()
if(!flowFile) return
flowFile = session.putAllAttributes(flowFile, attrMap)
&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;grovy code below to run java jar &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;def command = &lt;/CODE&gt;&lt;CODE&gt;"java -jar UpdateAppIdXMLRequest.jar file.xml"&lt;/CODE&gt; &lt;BR /&gt;&lt;CODE&gt;def process = command.execute()&lt;/CODE&gt; &lt;BR /&gt;&lt;CODE&gt;process.waitFor()&lt;/CODE&gt; &lt;BR /&gt;&lt;CODE&gt;def output = process.in.text&lt;/CODE&gt; &lt;BR /&gt;&lt;CODE&gt;log.info output&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;my question is how to pass flow file to java jar command. Shall i deserilized to disk and pass as file to java command as input file?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2018 19:48:30 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Processor-to-run-java-code-jar-file-in-apache-nifi/m-p/110283#M50719</guid>
      <dc:creator>ashutosh_pathak</dc:creator>
      <dc:date>2018-02-20T19:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: Processor to run java code / jar file in apache nifi</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Processor-to-run-java-code-jar-file-in-apache-nifi/m-p/331145#M50720</link>
      <description>&lt;P&gt;Hello Team, I am facing some problem while running JAR file from NIFI. please find below screenshot for same&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="abhiCoder_0-1638161470940.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/32931i055FA403219CB74B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="abhiCoder_0-1638161470940.png" alt="abhiCoder_0-1638161470940.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;could anyone help for same?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 04:51:23 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Processor-to-run-java-code-jar-file-in-apache-nifi/m-p/331145#M50720</guid>
      <dc:creator>abhiCoder</dc:creator>
      <dc:date>2021-11-29T04:51:23Z</dc:date>
    </item>
  </channel>
</rss>

