1

I'm trying to create a Kafka Streams application with Java and having a hard time managing the dependencies. Please let me say that I am completely noob to Java and it's ecosystem of tools.

The project is compiled with Maven and I'm using IntelliJ Idea. The project is configured to use OpenJDK 14.

Here's the 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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.petite</groupId>
    <artifactId>ora</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>14</source>
                    <target>14</target>
                </configuration>
            </plugin>
        </plugins>
        <defaultGoal>compile</defaultGoal>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-clients</artifactId>
            <version>2.5.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-streams</artifactId>
            <version>2.5.0</version>
        </dependency>
    </dependencies>
</project>

With this setup I can print a "Hello world!" to the console but as soon as I import Kafka Streams classes errors start to pop up:

package com.petite;

import org.apache.kafka.streams.KafkaStreams;
import org.apache.kafka.streams.kstream.StreamsBuilder;
import org.apache.kafka.streams.processor.Topology;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello from Java");
    }
}

IntelliJ tells me that it can't find the symbols StreamsBuilder and Topology. Now being a complete alien to Java, IntelliJ and Maven I really can't find a way to go forward.

How come the dependencies shown on Kafka site (https://kafka.apache.org/25/documentation/streams/developer-guide/write-streams.html#libraries-and-maven-artifacts) can be downloaded but can't be imported?

Élodie Petit
  • 5,774
  • 6
  • 50
  • 88
  • Did you try mvn clean install , also once check in the product structure in external libraries that these jars have been downloaded or not – Ishant Gaurav Jun 05 '20 at 08:15

1 Answers1

2

You StreamsBuilder and Topology are under stream package and not in kstream and processor

Use the below imports :

import org.apache.kafka.streams.StreamsBuilder;
import org.apache.kafka.streams.Topology;

And as you mentioned that you are new to Java, just an torubleshoot advice , if you ever face such issues just delete the import then modern IDE like Inteliij will automatically show the option.

Ishant Gaurav
  • 1,183
  • 2
  • 13
  • 32