You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vert.x Scala启动报错:找不到io.vertx.core.Launcher主类

解决Vert.x Scala项目中io.vertx.core.Launcher找不到的问题

问题根源

运行报错ClassNotFoundException: io.vertx.core.Launcher,本质是项目运行时类路径中缺少包含该类的Vert.x Core依赖。你在project/Build.scala里只是配置了主类的类名,但没有在项目依赖中引入对应的库,导致JVM找不到这个类。


具体解决步骤

1. 补充Vert.x Core依赖

打开项目根目录下的build.sbt,添加Vert.x Core的依赖项,版本要和项目中已有的Vert.x Scala依赖保持一致。比如你的项目里定义了val vertxVersion = "4.5.1"(根据实际版本调整),添加以下代码:

libraryDependencies += "io.vertx" % "vertx-core" % vertxVersion

注:虽然vertx-lang-scala会间接依赖vertx-core,但显式添加能避免依赖解析异常,确保类路径包含该库。

2. 修复Scala 3编译选项警告

你看到的bad option '-target:17' was ignored警告,是因为Scala 3废弃了-target参数,改用-release指定目标JVM版本。修改project/Build.scala中的scalacOptions:

scalacOptions ++= Vector(
  "-unchecked",
  "-deprecation",
  "-release:17", // 替换原来的"-target:17"
  "-encoding", "UTF-8"
)

3. 重新启动项目

在sbt控制台执行:

reStart

此时io.vertx.core.Launcher会被正确加载,项目即可正常启动。


额外验证

确认build.sbt中已正确启用Build插件并配置主Verticle(脚手架生成的项目一般自带,但缺失的话需要补上):

enablePlugins(Build)
mainVerticle := "vertx.scala.myapp.HttpVerticle"

内容的提问来源于stack exchange,提问作者Ronaldo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 16:50:17