我一直在尝试启动一个java应用程序,它通过命令向docker compose中的kafka代理生成消息。但是,我遇到了一些问题,它似乎不了解org.apache。kafka:kafka-clients:2.5.0依赖项(或更多),但它已与此依赖项断开。
我的应用程序目录中的dockerfile
FROM maven:3.5-jdk-9 as maven
COPY ./pom.xml ./pom.xml
RUN mvn dependency:go-offline -B
COPY ./src ./src
RUN mvn package
FROM openjdk:8u171-jre-alpine
WORKDIR /my-app
COPY --from=maven target/my-app-*.jar ./
COPY --from=maven src/main/java/ ./
COPY --from=maven target/classes/ ./
RUN apk add --no-cache nss
CMD ["java", "-jar", "./target/my-app-1.0-SNAPSHOT.jar"]
docker-compose.yml文件(特定服务)
javapublisher:
image: java-kafka-producer:1.0-SNAPSHOT
container_name: javapublisher
depends_on:
- kafka
- zookeeper
networks:
- localnet
command : > ls
&& java -jar my-app-1.0-SNAPSHOT.jar"
运行后出错 docker-compose up
```
javapublisher | Creating Kafka Producer ...
javapublisher | Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/kafka/common/serialization/StringSerializer
javapublisher | at com.mycompany.app.KafkaProducerVibration.main(KafkaProducerVibration.java:24)
javapublisher | Caused by: java.lang.ClassNotFoundException: org.apache.kafka.common.serialization.StringSerializer
javapublisher | at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
javapublisher | at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
javapublisher | at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
javapublisher | at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
javapublisher | ... 1 more
javapublisher exited with code 1
暂无答案!
目前还没有任何答案,快来回答吧!