当前位置: 首页 > 知识库问答 >
问题:

NiFI自定义处理器ClassNotFoundException

何涵忍
2023-03-14

我试图加载一个自定义的NiFi处理器,但无法让NiFi加载所有的.nar依赖项,尽管尝试了各种pom.xml配置。我在SO上遇到过一些类似的问题,但还没有找到这个问题的答案。

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <nifi.version>1.1.2</nifi.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-api</artifactId>
        <version>${nifi.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-utils</artifactId>
        <version>${nifi.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-standard-services-api-nar</artifactId>
        <version>${nifi.version}</version>
        <type>nar</type>
    </dependency>
    <dependency>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-ssl-context-service</artifactId>
        <version>${nifi.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-ssl-context-service-api</artifactId>
        <version>${nifi.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-processor-utils</artifactId>
        <version>${nifi.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.4.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.4.1</version>
    </dependency>
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.9.7</version>
    </dependency>
</dependencies>
bcpkix-jdk15on-1.55.jar                joda-time-2.9.7.jar
bcprov-jdk15on-1.55.jar                nifi-api-1.1.2.jar
commons-codec-1.9.jar                  nifi-processor-utils-1.1.2.jar
commons-io-2.5.jar                     nifi-security-utils-1.1.2.jar
commons-lang3-3.4.jar                  nifi-ssl-context-service-1.1.2.jar
commons-logging-1.2.jar                nifi-ssl-context-service-api-1.1.2.jar
httpclient-4.4.1.jar                   nifi-utils-1.1.2.jar
httpcore-4.4.1.jar
2017-03-13 11:11:23,146 ERROR [main] org.apache.nifi.NiFi Failure to launch NiFi due to java.util.ServiceConfigurationError: org.apache.nifi.processor.Processor: Provider com.alar.nifi.processors.GetIBright could not be instantiated
java.util.ServiceConfigurationError: org.apache.nifi.processor.Processor: Provider com.alar.nifi.processors.GetIBright could not be instantiated
    at java.util.ServiceLoader.fail(ServiceLoader.java:232) ~[na:1.8.0_111]
    at java.util.ServiceLoader.access$100(ServiceLoader.java:185) ~[na:1.8.0_111]
    at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384) ~[na:1.8.0_111]
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404) ~[na:1.8.0_111]
    at java.util.ServiceLoader$1.next(ServiceLoader.java:480) ~[na:1.8.0_111]
    at org.apache.nifi.nar.ExtensionManager.loadExtensions(ExtensionManager.java:116) ~[nifi-nar-utils-1.1.2.jar:1.1.2]
    at org.apache.nifi.nar.ExtensionManager.discoverExtensions(ExtensionManager.java:97) ~[nifi-nar-utils-1.1.2.jar:1.1.2]
    at org.apache.nifi.NiFi.<init>(NiFi.java:139) ~[nifi-runtime-1.1.2.jar:1.1.2]
    at org.apache.nifi.NiFi.main(NiFi.java:262) ~[nifi-runtime-1.1.2.jar:1.1.2]
Caused by: java.lang.NoClassDefFoundError: org/apache/http/conn/HttpClientConnectionManager
    at java.lang.Class.getDeclaredConstructors0(Native Method) ~[na:1.8.0_111]
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) ~[na:1.8.0_111]
    at java.lang.Class.getConstructor0(Class.java:3075) ~[na:1.8.0_111]
    at java.lang.Class.newInstance(Class.java:412) ~[na:1.8.0_111]
    at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380) ~[na:1.8.0_111]
    ... 6 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.apache.http.conn.HttpClientConnectionManager
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_111]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_111]
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_111]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_111]
    ... 11 common frames omitted

共有1个答案

郁隐水
2023-03-14

通过将单个pom.xml修改为单独的build(nar)和compile(jar)pom.xml文件以及父pom.xml文件,解决了这个问题。我不知道为什么它以前不能工作,但我在下面包含了pom.xml文件

父pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>nifi-ibright-bundle</artifactId>
    <packaging>pom</packaging>
    <groupId>com.alar.nifi</groupId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <nifi.version>1.1.2</nifi.version>
    </properties>

    <modules>
        <module>nifi-ibright-processor</module>
        <module>nifi-ibright-nar</module>
    </modules>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.alar.nifi</groupId>
                <artifactId>nifi-ibright-processor</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
        </dependencies>
    </dependencyManagement> 
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.nifi</groupId>
                <artifactId>nifi-nar-maven-plugin</artifactId>
                <version>1.0.0-incubating</version>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.15</version>
            </plugin>
        </plugins>
    </build>
</project>

nifi-iBright-nar/pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>com.alar.nifi</groupId>
        <artifactId>nifi-ibright-bundle</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.alar.nifi</groupId>
    <artifactId>nifi-ibright-processor</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>


    <dependencies>
        <dependency>
            <groupId>org.apache.nifi</groupId>
            <artifactId>nifi-api</artifactId>
            <version>${nifi.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.nifi</groupId>
            <artifactId>nifi-utils</artifactId>
            <version>${nifi.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.nifi</groupId>
            <artifactId>nifi-ssl-context-service-api</artifactId>
            <version>${nifi.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.nifi</groupId>
            <artifactId>nifi-processor-utils</artifactId>
            <version>${nifi.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.4.1</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.9.7</version>
        </dependency>
    </dependencies>

</project>
 类似资料:
  • 我使用的是Nifi 0.4.1版本。我写自定义代码转换CSV到avro格式。我已经创建了类文件,并能够生成nar文件。将nar文件放置在lib目录中,并重新启动nifi服务器。 任何帮助都很感激.. 谢谢,

  • 我正在构建一个自定义处理器来处理流文件,为了处理流文件,我需要从我的本地文件系统读取CSV文件。我创建了一个proerty描述符CSV_PATH,如下所示 现在我想在配置处理器时获取在UI中设置的CSV_PATH属性的值。我无法获得CSV_PATH值。另外,如果我在代码中硬编码filepath,那么我仍然无法从本地文件系统读取CSV。

  • 我正在研究创建一个自定义处理器从一个自定义源中摄取数据,那里没有现有的nifi处理器。 我一直试图理解Nifi组件如何工作的机制,并看到了一些关于如何创建自定义处理器的好文档,然而,我看不到任何关于管理偏移量的内容。假设我有一个运行1秒的处理器,但需要从某个任意偏移量继续进行处理,这可能会每秒钟产生结果,也可能不会产生结果。

  • 我能够在eclipse中远程调试apache nifi自定义处理器(参考:1、2、3)。我遵循的步骤如下: > 取消apache nifi bootstrap.conf中行下的注释 启动apache nifi