Vert.x Kotlin 项目部署在 Docker
Vert.x project in Kotlin deploy in Docker
我有一个用 Kotlin 的 vert.x 框架编写的项目。我构建了 jar 文件,我想通过 Docker 运行 这个 jar。但是 docker 找不到我的主 Verticle 文件。
Docker文件:
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"]
我的主 Verticle 的路径
com.mycompany.department.OpenApiRoutingVerticle
PS 错误是:
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(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)
请尝试替换行 ENV VERTICLE_NAME OpenApiRoutingVerticle.kt
ENV VERTICLE_NAME com.mycompany.department.OpenApiRoutingVerticle
kotlin 文件被编译为一个 .class 文件,只要您提供 class 路径位置,就应该选择该文件。
我有一个用 Kotlin 的 vert.x 框架编写的项目。我构建了 jar 文件,我想通过 Docker 运行 这个 jar。但是 docker 找不到我的主 Verticle 文件。
Docker文件:
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"]
我的主 Verticle 的路径
com.mycompany.department.OpenApiRoutingVerticle
PS 错误是:
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(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)
请尝试替换行 ENV VERTICLE_NAME OpenApiRoutingVerticle.kt
ENV VERTICLE_NAME com.mycompany.department.OpenApiRoutingVerticle
kotlin 文件被编译为一个 .class 文件,只要您提供 class 路径位置,就应该选择该文件。