0

I'm trying to containerise a kafka consumer using docker. I'm using a multistage docker file to do this, but I'm grtting this error every time I run the command. The program runs fine when I try to run from the IDE but doesn't seem to work if I build it using maven and try running it using the Jar file.

I'm guess this is caused because the compiler doesn't see an executable jar file while searching for the given class and throws an exception. I tried out multiple solutions but nothing seemed to quite work.

Here's the pom.xml file

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.sweethome</groupId>
  <artifactId>notificationservice</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
         <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-clients</artifactId>
            <version>2.7.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
            <plugin>
               <!-- <groupId>org.apache.maven.plugins</groupId> -->
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>

                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.sweethome.notificationservice.Consumer</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>

                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>install</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>

            </plugin>
            <plugin>   
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.sweethome.notificationservice.Consumer</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
        <finalName>notificationService</finalName>
    </build>
    <properties>
        <java.version>11</java.version>
    </properties>
    
</project>

Help! :')

Tried out multiple solutions from here but it did not work.

samix98
  • 11
  • 1
  • Chances are the issue is that the JVM doesn't have the `kafka-clients` jar on its classpath. However, to know more you'll need to post the command you're running, and directory layout and contents of the docker image, e.g. are you adding all your jars into a `lib` directory? – Andrew Coates Feb 07 '23 at 18:18
  • 1
    You are right. The Jar file was getting built for the kafka-client dependency. The issue was with the maven command I was using. It's working now. I was just doing mvn clean package earlier. It worked when I used mvn clean compile assembly:single – samix98 Feb 08 '23 at 19:16
  • BTW, look at Jib maven plugin to build containers. – OneCricketeer Feb 09 '23 at 00:57

0 Answers0