I trying to start my app using docker. App consist of MonoThreadClientHandler.java and tcp_server.java (https://github.com/MikhailYuzhakov/tcp_server/tree/master). Dockerfile:
FROM alpine:latest
RUN apk update && apk upgrade && apk add git
RUN apk update && apk add openjdk11
RUN apk update && apk add bash
RUN git init && git remote add origin https://github.com/MikhailYuzhakov/tcp_server.git && git pull origin master
RUN javac -classpath ./json-simple-1.1.1.jar -d . MonoThreadClientHandler.java && javac -d . tcp_server.java
CMD ["java", "tcp_server"]
I compile with dependencies using -classpath. When app is running and client try connect to server, I get error code:
Server 2.0 socket 0.0.0.0/0.0.0.0:3345 created
Connection with /45.137.112.110:61395 accepted.Exception in thread "pool-1-thread-1" java.lang.NoClassDefFoundError: org/json/simple/parser/JSONParser
at Database.parseDate(MonoThreadClientHandler.java:95)
at MonoThreadClientHandler.run(MonoThreadClientHandler.java:28)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.ClassNotFoundException: org.json.simple.parser.JSONParser
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 5 more
I try modife compile command javac with -d, -cp, -classpath and etc., but no result.
Compilation worked fine. You aren't specifying a classpath with your CMD
. You could specify it with ENV
. And you could also combine your javac
commands. Like,
ENV CLASSPATH=.:./json-simple-1.1.1.jar
RUN javac -d . MonoThreadClientHandler.java tcp_server.java
CMD ["java", "tcp_server"]