Support Questions

Find answers, ask questions, and share your expertise
Announcements
We’ve updated our product names and community labels - click here for full details

Building Custom NAR - How to add config sub directory into NAR?

avatar
Explorer

HI,

I have built a custom processor that uses another java library. This 3rd party JAR requires one sub directory ./data containing a file named config.ini.

I put the NAR into the ./extensions subfolder of NiFi. When NiFi starts up, it unpacks the NAR  into the folder 

nifi/work/nar/extensions/my-processor-nar-1.0.nar-unpacked/

This folder contains a subfolder NAR-INF.

And this NAR-INF is the location where my subfolder "data" needs to be copied. When I manually copy the folder with the containing config file into NAR-INF, the processor works fine.

But after the next restart of NiFi the subfolder is missing again.

I need the structure of the unpacked NAR to include this:

nifi/work/nar/extensions/my-processor-nar-1.0.nar-unpacked/data/config.ini

Does anyone have an example how I can build the NAR so that this subfolder and file are included?
Like an example pom.xml snippet?

Cheers,
Karsten

1 ACCEPTED SOLUTION

avatar
Master Collaborator

Hello @karsten

You should not include anything under the unpacked folder, after a restart it will always remove the content and the new unpack will put only the nar content. 

Now, you can use the resources path for this, for example: 

├── your-nifi-custom-processor
│   ├── pom.xml
│   └── src
│       └── main
│           ├── java
│           ├── resources
│               └── data
│           │       └── config.ini
│           └── webapp

This is based on the examples here: https://nifi.apache.org/docs/nifi-docs/html/developer-guide.html

You should include all the information on your pom.xml. The resources part should look like this: 

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*</include>
            </includes>
        </resource>
    </resources>

Also found this interesting blog with the same explanation: https://medium.com/@mr.sinchan.banerjee/nifi-custom-processor-series-part-1-writing-your-first-custo...
This is not Cloudera or NiFi official, but it could help you. 


Regards,
Andrés Fallas
--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs-up button.

View solution in original post

2 REPLIES 2

avatar
Master Collaborator

Hello @karsten

You should not include anything under the unpacked folder, after a restart it will always remove the content and the new unpack will put only the nar content. 

Now, you can use the resources path for this, for example: 

├── your-nifi-custom-processor
│   ├── pom.xml
│   └── src
│       └── main
│           ├── java
│           ├── resources
│               └── data
│           │       └── config.ini
│           └── webapp

This is based on the examples here: https://nifi.apache.org/docs/nifi-docs/html/developer-guide.html

You should include all the information on your pom.xml. The resources part should look like this: 

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*</include>
            </includes>
        </resource>
    </resources>

Also found this interesting blog with the same explanation: https://medium.com/@mr.sinchan.banerjee/nifi-custom-processor-series-part-1-writing-your-first-custo...
This is not Cloudera or NiFi official, but it could help you. 


Regards,
Andrés Fallas
--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs-up button.

avatar
Explorer

Thank you André,

This led to the right direction.
Since the configuration file is required by a third party JAR that I don't build, the way to solve it was to add a src/main/resources path to the myProcessor-nar directory instead of the myProcessor-processor directory. The nar directory doesn't include a src/main/java but you can nevertheless add a src/main/resources path and add subfolders/files to it, e.g. NAR-INF/data/config.ini.

Maven will copy automatically everything under src/main/resources to the target, hence it's not necessary to add the resources snippet to the pom.xml.

So, now NiFi's work/nar/extensions/myProcessor-nar-1.0.nar-unpacked/NAR-INF folder contains my subfolder/file data/config.ini every time NiFi unpacks the NAR.

I found this article helpful that explains the parts of a NAR and the three pom.xml files: https://www.javahotchocolate.com/notes/nifi-project.html

Thanks @vafs!