[英]Apache NiFi Custom NAR NoClassDefFoundError During Startup
I am attempting to install a custom NAR controller service bundle in my NiFi installation but get this error during startup.我正在尝试在 NiFi 安装中安装自定义 NAR 控制器服务包,但在启动过程中出现此错误。 It acts like it can't find the
RecordReaderFactory
class from the nifi-record-serialization-service-api
even though it is included as a dependency:它的行为就像无法从
nifi-record-serialization-service-api
找到RecordReaderFactory
类,即使它作为依赖项包含在内:
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-record-serialization-service-api</artifactId>
<version>1.9.0</version>
</dependency>
Here is the project: https://github.com/adamfisher/nifi-zonefile-record-serialization-service这是项目: https : //github.com/adamfisher/nifi-zonefile-record-serialization-service
Running maven install
builds the NAR successfully.运行
maven install
成功构建 NAR。 It's just when I startup NiFi, it gives this error.只是当我启动 NiFi 时,它会出现此错误。 I'm pretty sure this is a maven POM configuration issue.
我很确定这是一个 Maven POM 配置问题。 I just don't work with Java too much and hoping someone can shed some light on why it is not finding the dependent class it needs?
我只是不太会使用 Java,希望有人能解释为什么它没有找到它需要的依赖类?
nifi-app.log: nifi-app.log:
2019-03-02 15:22:15,245 INFO [main] org.apache.nifi.web.server.JettyServer Loading WAR: D:\nifi\NIFI-1~2.0\.\work\nar\framework\nifi-framework-nar-1.9.0.nar-unpacked\NAR-INF\bundled-dependencies\nifi-web-error-1.9.0.war with context path set to /
2019-03-02 15:22:15,261 INFO [main] org.apache.nifi.web.server.JettyServer Running in HTTP mode; host headers not restricted
2019-03-02 15:22:16,386 ERROR [main] org.apache.nifi.NiFi Failure to launch NiFi due to java.lang.NoClassDefFoundError: org/apache/nifi/serialization/RecordReaderFactory
java.lang.NoClassDefFoundError: org/apache/nifi/serialization/RecordReaderFactory
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:370)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at org.apache.nifi.nar.StandardExtensionDiscoveringManager.loadExtensions(StandardExtensionDiscoveringManager.java:152)
at org.apache.nifi.nar.StandardExtensionDiscoveringManager.discoverExtensions(StandardExtensionDiscoveringManager.java:127)
at org.apache.nifi.nar.StandardExtensionDiscoveringManager.discoverExtensions(StandardExtensionDiscoveringManager.java:113)
at org.apache.nifi.web.server.JettyServer.start(JettyServer.java:925)
at org.apache.nifi.NiFi.<init>(NiFi.java:158)
at org.apache.nifi.NiFi.<init>(NiFi.java:72)
at org.apache.nifi.NiFi.main(NiFi.java:297)
Caused by: java.lang.ClassNotFoundException: org.apache.nifi.serialization.RecordReaderFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 23 common frames omitted
2019-03-02 15:22:16,387 INFO [Thread-1] org.apache.nifi.NiFi Initiating shutdown of Jetty web server...
2019-03-02 15:22:16,387 INFO [Thread-1] org.apache.nifi.NiFi Jetty web server shutdown completed (nicely or otherwise).
The NAR dependencies are used at runtime to create a chain of parent class loaders. NAR 依赖项在运行时用于创建父类加载器链。 So in your example you have
所以在你的例子中你有
nifi-zonefile-record-serialization-service-nar -> (depends on) nifi-zonefile-record-serialization-service-nar ->(取决于)
nifi-zonefile-record-serialization-service-api-nar -> (depends on) nifi-zonefile-record-serialization-service-api-nar ->(取决于)
nifi-standard-services-api-nar nifi-standard-services-api-nar
In the running application when it instantiates the instance of your record reader from your service NAR, it then needs to load the interface that implements which comes from your service API NAR, which then needs to load the RecordReader interface which comes from the standard services API NAR.在运行的应用程序中,当它从您的服务 NAR 实例化您的记录读取器的实例时,它需要加载实现来自您的服务 API NAR 的接口,然后需要加载来自标准服务 API 的 RecordReader 接口纳尔。
I have spent a lot of time on this.我花了很多时间在这上面。 Finally, i have a working solution for me.
最后,我有一个可行的解决方案。 My custom processor is using RecordReader for incoming stream.
我的自定义处理器将 RecordReader 用于传入流。 However, either compile or package failed in maven process.
但是,在 maven 过程中编译或打包失败。 I had to customize pom.xml as following:
我必须自定义 pom.xml 如下:
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-record-serialization-service-api</artifactId>
<version>${nifi.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-record-serialization-services-nar</artifactId>
<version>${nifi.version}</version>
<type>nar</type>
</dependency>
I ended up needing to include the API NAR file as well even though it doesn't appear to be used anywhere.我最终也需要包含 API NAR 文件,即使它似乎没有在任何地方使用。 It's just a generic template class called
MyService
.它只是一个名为
MyService
的通用模板类。
I have the same issue as described here and I managed to solved it including the dependencies at the nar module(nifi-base-nar) pom.xml我有与这里描述的相同的问题,我设法解决了它,包括 nar 模块(nifi-base-nar)pom.xml 中的依赖项
The dependency that you need to include is the following:您需要包含的依赖项如下:
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-standard-services-api-nar</artifactId>
<version>${nifi.version}</version>
<type>nar</type>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.