2016-05-10 15 views
0

karaf 4.0.3でカフカプロデューサを作成しようとしています。 pom.xmlが含まれている私のKafka OSGIバンドル - プロデューサ初期化の問題でクラスorg.apache.kafka.clients.producer.ProducerConfigを初期化できませんでした

ClassLoader currentLoader; 
try{ 
    currentLoader = Thread.currentThread().getContextClassLoader(); 
    Thread.currentThread().setContextClassLoader(null); 
    Properties props = new Properties(); 
    props.put("bootstrap.servers","localhost:9092"); 
    props.put("value.serializer","org.apache.kafka.common.serialization.StringSerializer"); 
    props.put("key.serializer","org.apache.kafka.common.serialization.IntegerSerializer"); 

    KafkaProducer<String,String> producer = new KafkaProducer<String,String>(props); 
    Thread.currentThread().setContextClassLoader(currentLoader); 
    producer.close(); 

私も下のリンクでの回避策を試してみました

2016-05-09 14:18:12,127 | ERROR | nsole user karaf | ShellUtil      | 44 - org.apache.karaf.shell.core - 4.0.3 | Exception caught while executing command 
org.apache.karaf.shell.support.MultiException: Error executing command on bundles: 
Error starting bundle143: Activator start error in bundle KafkaArtifact [143]. 
at org.apache.karaf.shell.support.MultiException.throwIf(MultiException.java:61) 
at org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:69)[24:org.apache.karaf.bundle.core:4.0.3] 
at org.apache.karaf.bundle.command.BundlesCommand.execute(BundlesCommand.java:54)[24:org.apache.karaf.bundle.core:4.0.3] 
at org.apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:83)[44:org.apache.karaf.shell.core:4.0.3] 
at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:67)[44:org.apache.karaf.shell.core:4.0.3] 
at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:87)[44:org.apache.karaf.shell.core:4.0.3] 
at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)[44:org.apache.karaf.shell.core:4.0.3] 
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)[44:org.apache.karaf.shell.core:4.0.3] 
at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[44:org.apache.karaf.shell.core:4.0.3] 
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)[44:org.apache.karaf.shell.core:4.0.3] 
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)[44:org.apache.karaf.shell.core:4.0.3] 
at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)[44:org.apache.karaf.shell.core:4.0.3] 
at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java:270)[44:org.apache.karaf.shell.core:4.0.3] 
at java.lang.Thread.run(Thread.java:745)[:1.8.0_66] 
Caused by: java.lang.Exception: Error starting bundle143: Activator start error in bundle KafkaArtifact [143]. 
at org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:66)[24:org.apache.karaf.bundle.core:4.0.3] 
... 12 more 
Caused by: org.osgi.framework.BundleException: Activator start error in bundle KafkaArtifact [143]. 
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2276)[org.apache.felix.framework-5.4.0.jar:] 
at org.apache.felix.framework.Felix.startBundle(Felix.java:2144)[org.apache.felix.framework-5.4.0.jar:] 
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)[org.apache.felix.framework-5.4.0.jar:] 
at org.apache.karaf.bundle.command.Start.executeOnBundle(Start.java:38)[24:org.apache.karaf.bundle.core:4.0.3] 
at org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:64)[24:org.apache.karaf.bundle.core:4.0.3] 
... 12 more 
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.kafka.clients.producer.ProducerConfig 
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:181) 
at com.KafkaSample.KafkaArtifact.Producer.<init>(Producer.java:24) 
at com.KafkaSample.KafkaArtifact.KafkaConsumerProducerDemo.start(KafkaConsumerProducerDemo.java:9) 
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697) 
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2226) 
... 16 more 

<dependency> 
    <groupId>org.apache.kafka</groupId> 
    <artifactId>kafka-clients</artifactId> 
    <version>0.9.0.0</version> 
</dependency> 

コードを展開、私は以下のエラーを取得していますが、

Karaf - Kafka OSGI bundle - Producer issue

しかし、まだ同じエラーが発生しています。

答えて

-1

私はその3ヶ月の問題を知っています。でも、私はこのプロデューサーの問題に悩まされました。 2日間掘り起こした後、誰かがこの問題についてすでに言及している解決策がパッチされているが、2.18.0バージョンのラクダのライブラリで利用できるようになるジラの問題に遭遇した。これを解決するには、this camel repositoryをクローンし、私のプロジェクトに必要なコンポーネントをビルドすることでした。これらのコンポーネントは、現時点では2.18.0-SNAPSHOTバージョンです。 componentsフォルダの下で、必要なコンポーネントを選択し、maven cleanパッケージを実行して、ターゲットディレクトリに生成されたjarファイルを取得します。

コンパイルするときにもう1つ、camel-core sub project。それはあなたがそれを必要としないかもしれない多くのテストケースを実行するので、プロパティの最後の行で ""を "org/apache/camel/**/*。java"に置き換えてください。 これが役立つことを願っています。

関連する問題