gpt4 book ai didi

java - 为什么 docker-maven-plugin 无法获取正确的 jar 文件以包含在 docker 镜像中?

转载 作者:行者123 更新时间:2023-12-05 05:12:11 25 4
gpt4 key购买 nike

据我了解构建流程:

  1. maven-assembly-plugin 构建 /target/my-artifact-1.0-SNAPSHOT-jar-with-dependencies.jar

    <
  2. maven-jar-plugin 构建 /target/my-artifact-1.0-SNAPSHOT.jar(不确定我们为什么需要它)

  3. docker-maven-plugin 假设为 assemble 带有依赖关系的 Artifact /target/my-artifact-1.0-SNAPSHOT-jar-with-dependencies.jar

然而,出于某种原因,它选择了错误的 jar Artifact 。

我错过了什么?如何让它发挥作用?

pom.xml

<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.20.1</version>
<extensions>true</extensions>
<configuration>
<images>
<image>
<name>my-artifact</name>
<build>
<from>java:8-jre</from>
<volumes>
<volume>/target</volume>
</volumes>
<entryPoint>
<exec>
<arg>java</arg>
<arg>-jar</arg>
<arg>/target/my-artifact-1.0-SNAPSHOT-jar-with-dependencies.jar</arg>
</exec>
</entryPoint>
<assembly>
<descriptorRef>artifact-with-dependencies</descriptorRef>
<targetDir>/target</targetDir>
<mode>dir</mode>
<!--<basedir>/target</basedir>-->
</assembly>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>docker-build</id>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>docker:start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>docker:stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>create-archive</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>Client</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>Client</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

最佳答案

要引用文档,:

     <descriptorRef>artifact-with-dependencies</descriptorRef>

will add the created artifact with the name ${project.build.finalName}.${artifact.extension} and all jar dependencies in the the targetDir (which is /maven by default).

这不是你想要的。

我认为你想要的是将程序集自定义为这样的东西:

<assembly>
<targetDir>/target</targetDir>
<inline>
<fileSets>
<fileSet>
<directory>${project.basedir}/target/</directory>
<outputDirectory>.</outputDirectory>
<includes>
<include>project-name-version-classifier-jar-with-dependencies.jar</include>
</includes>
</fileSet>
</fileSets>
</inline>
</assembly>

奖励点:看看Jib ,如果您正在为 Java 项目构建图像,它可能更适合您的需求。

关于java - 为什么 docker-maven-plugin 无法获取正确的 jar 文件以包含在 docker 镜像中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54841653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com