简体   繁体   English

Gradle Shadow Plugin.jar 未在 Docker 容器上运行,没有主清单属性

[英]Gradle Shadow Plugin .jar not running on Docker container, no main manifest attribute

I built a fat jar using the Gradle Shadow Plugin like so:我像这样使用Gradle Shadow 插件构建了一个胖子 jar:

tasks {
    "build" {
        dependsOn(shadowJar)
    }
    shadowJar {
        mergeServiceFiles {
            var path = "META-INF/"
        }
        manifest.inheritFrom(jar.get().manifest)
        manifest.attributes["Main-Class"] = "some.main.class.Main"
        manifest.attributes["Implementation-Version"] = version
    }
}

This works with no problem when I do gradle build and then java -jar fat_jar_name.jar , I have tested in MacOS , Windows and Ubuntu (WSL) .当我执行gradle build然后java -jar fat_jar_name.jar时,这没有问题,我已经在MacOSWindowsUbuntu (WSL)中进行了测试。 The same command works exactly the same on all those platforms, even if the.jar was not locally built, but for some reason it is not working in Docker with eclipse-temurin .相同的命令在所有这些平台上的工作方式完全相同,即使 .jar 不是本地构建的,但由于某种原因它在Dockereclipse-temurin中不起作用。

I am trying to run a.jar file within Docker using:我正在尝试使用以下命令在 Docker 中运行 a.jar 文件:

FROM eclipse-temurin:17
ARG JAR_FILE=build/libs/*jar
COPY ${JAR_FILE} fat_jar_name-all.jar

ENTRYPOINT java -jar fat_jar_name.jar

I build the image using docker image build -t image_name.我使用docker image build -t image_name. , and then I am trying to run it using docker run -d -p 8080:8080 image_name . ,然后我尝试使用docker run -d -p 8080:8080 image_name来运行它。

I get this error when running:运行时出现此错误:

no main manifest attribute, in fat_jar_name-all.jar

I found that this issue is related to not having a META-INF\MANIFEST.MF file in the exported .jar .我发现此问题与导出的.jar中没有META-INF\MANIFEST.MF文件有关。 However, the fat_jar_name.jar does contain a manifest file with these contents:但是, fat_jar_name.jar确实包含具有以下内容的清单文件:

Manifest-Version: 1.0
Main-Class: some.main.class.Main
Implementation-Version: 3.9.1-SNAPSHOT

Is there something I'm missing at the Docker , Gradle or Shadow Plugin level to make this work?我在DockerGradleShadow Plugin级别是否缺少某些东西来使这项工作正常进行?

I found this resource for the Shadow Plugin about configuring the manifest, but it makes no mention of a main manifest attribute .我找到了有关配置清单的Shadow Plugin 资源,但它没有提及main manifest attribute

I found that the COPY command I was using was broken.我发现我使用的COPY命令被破坏了。 I used this one instead:我改用这个:

FROM eclipse-temurin:17
COPY build/libs/fat_jar_name-all.jar /
ENTRYPOINT java -jar fat_jar_name-all.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM