Search code examples
dockerdeploymentkotlinvert.xvertx-verticle

Vert.x project in Kotlin deploy in Docker


I have a project written in vert.x framework in Kotlin. I build jar file, and I want to run this jar through Docker. But docker can't find my main Verticle file.

Dockerfile:

FROM vertx/vertx3

ENV VERTICLE_NAME OpenApiRoutingVerticle.kt
ENV VERTICLE_FILE build/libs/vertx-kotlin-project-1.0-SNAPSHOT.jar
ENV VERTICLE_HOME /usr/verticles
EXPOSE 8080
COPY  $VERTICLE_FILE $VERTICLE_HOME/
WORKDIR $VERTICLE_HOME
ENTRYPOINT ["sh", "-c"]
CMD ["exec vertx run $VERTICLE_NAME -cp $VERTICLE_HOME/* $VERTX_OPTIONS"]

Path to my main verticle

 com.mycompany.department.OpenApiRoutingVerticle

PS the error is:

java.lang.IllegalStateException: Cannot find verticle script: OpenApiRoutingVerticle.kt on classpath
    at io.vertx.lang.kotlin.KotlinVerticleFactory.createVerticle(KotlinVerticleFactory.kt:28)
    at io.vertx.core.impl.DeploymentManager.createVerticles(DeploymentManager.java:229)
    at io.vertx.core.impl.DeploymentManager.lambda$doDeployVerticle$2(DeploymentManager.java:202)
    at io.vertx.core.impl.FutureImpl.setHandler(FutureImpl.java:76)
    at io.vertx.core.impl.DeploymentManager.doDeployVerticle(DeploymentManager.java:171)
    at io.vertx.core.impl.DeploymentManager.doDeployVerticle(DeploymentManager.java:143)
    at io.vertx.core.impl.DeploymentManager.deployVerticle(DeploymentManager.java:131)
    at io.vertx.core.impl.VertxImpl.deployVerticle(VertxImpl.java:665)
    at io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer.deploy(VertxIsolatedDeployer.java:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at io.vertx.core.impl.launcher.commands.ClasspathHandler.deploy(ClasspathHandler.java:159)
    at io.vertx.core.impl.launcher.commands.RunCommand.deploy(RunCommand.java:397)
    at io.vertx.core.impl.launcher.commands.RunCommand.run(RunCommand.java:270)
    at io.vertx.core.impl.launcher.VertxCommandLauncher.execute(VertxCommandLauncher.java:226)
    at io.vertx.core.impl.launcher.VertxCommandLauncher.dispatch(VertxCommandLauncher.java:361)
    at io.vertx.core.impl.launcher.VertxCommandLauncher.dispatch(VertxCommandLauncher.java:324)
    at io.vertx.core.Launcher.main(Launcher.java:45)

Solution

  • Please try to replace the line ENV VERTICLE_NAME OpenApiRoutingVerticle.kt with ENV VERTICLE_NAME com.mycompany.department.OpenApiRoutingVerticle

    The kotlin file is compiled to a .class file which should be picked up as long as you provide the classpath location.