NiFI自定义处理器ClassNotFoundException

时间:2017-03-13 16:17:26

标签: java apache-nifi

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

我使用mvn clean install将处理器打包为.nar,然后将.nar复制到NIFI_HOME / lib。目前我得到java.lang.ClassNotFoundException: org.apache.http.conn.HttpClientConnectionManager。当前的pom依赖:

<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>

我的nar的NIFI_HOME /.../ bundled-dependencies /包含所有指定的jar:

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 个答案:

答案 0 :(得分:2)

通过使用父pom.xml将我的单个pom.xml修改为单独的build(nar)和compile(jar)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>