【发布时间】:2020-02-05 14:16:26
【问题描述】:
我用 gradle 构建了我的 spring-boot api 的 jar,但是在启动 docker 容器后它会自行停止并显示“错误:无法找到或加载主类 com.test.exampleController”
这是一个 Docker 项目
我将此代码插入到我的 build.gradle 中:
task fatJar(type: Jar) {
manifest {
attributes 'Main-Class': 'com.test.exampleController'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
我不确定我是否需要在课堂上进行一些注释,或者问题是因为我有 3 个控制器
我希望使用 tha spring-boot api 运行一个 docker 容器,并使用其他应用程序(例如邮递员)对其进行测试
【问题讨论】:
-
不要编写自己的任务。 gradle spring boot 任务完成了所有这些。所以放弃你的
fatJar任务,只使用spring boot任务(如果你简单地添加插件,它将默认执行)。 -
我尝试使用 gradle 任务生成 jar 文件,但没有生成任何内容。我按照以下步骤操作: gradle tab --> projectName --> Tasks --> build --> jar 我认为我的 build.gradle 中需要一个 instruccion 缺失,你能给我一个例子吗?感谢您的回复。
-
好吧,我终于找到了我的 gradle 中缺少的代码:``` jar { baseName = 'example-api' version = '0.1.0' } ``
-
应用 spring boot 插件,只需执行
gradle build即可。它将采用默认值(名称和组)来生成工件。
标签: java spring-boot docker gradle jar