Can you share some more details about what you're trying to do? How are you compiling/building your code? Are you trying to build a NiFi ARchive (NAR) that contains components such as processors and/or controller services? If so, this blog shows how to set up a Maven project to do so, and you can include your dependencies there (they will be included in the NAR and unpacked when the NAR is loaded).
If instead you need to be able to access JARs at runtime that will not be there during compilation, you can offer a property for "Additional resources" or whatever, and create a classloader at runtime that will include those paths. See ClassloaderUtils.getCustomClassLoader() or ScriptingComponentHelper.setupEngines() for more information. ExecuteScript and JoltTransformJSON are examples of processors that use these methods.