Home > Enterprise >  NoClassDefFoundError: scala/collection/convert/AsJavaExtensions
NoClassDefFoundError: scala/collection/convert/AsJavaExtensions

Time:09-17

I am creating EmbeddedKafkaCluster in Java test, but getting the following exception, but I have added the kafka_2.12 depedencies which have scala depedencies.

Java version: 11

Added the following depedencies

<!--Kafka Embedded Cluster dependencies -->
<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka_2.12</artifactId>
    <version>${kafka.version}</version>
    <classifier>test</classifier>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka_2.12</artifactId>
    <version>${kafka.version}</version>
    <scope>test</scope>
</dependency>

Exception:

java.lang.NoClassDefFoundError: scala/collection/convert/AsJavaExtensions

    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:315)
    at kafka.utils.Log4jControllerRegistration$.<clinit>(Logging.scala:28)
    at kafka.zk.EmbeddedZookeeper.<init>(EmbeddedZookeeper.scala:37)
    at org.apache.kafka.streams.integration.utils.EmbeddedKafkaCluster.start(EmbeddedKafkaCluster.java:89)
    at org.apache.kafka.streams.integration.utils.EmbeddedKafkaCluster.before(EmbeddedKafkaCluster.java:167)
    at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:50)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: java.lang.ClassNotFoundException: scala.collection.convert.AsJavaExtensions
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 16 more

CodePudding user response:

Upgrading to kafka_2.13 solved the issue.

<!--Kafka Embedded Cluster dependencies -->
<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka_2.13</artifactId>
    <version>${kafka.version}</version>
    <classifier>test</classifier>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka_2.13</artifactId>
    <version>${kafka.version}</version>
    <scope>test</scope>
</dependency>
  • Related