据我了解构建流程:
maven-assembly-plugin
构建/target/my-artifact-1.0-SNAPSHOT-jar-with-dependencies.jar
maven-jar-plugin
构建/target/my-artifact-1.0-SNAPSHOT.jar
(不确定我们为什么需要它)
docker-maven-plugin
假定为assemble artifact-with-dependencies
/target/my-artifact-1.0-SNAPSHOT-jar-with-dependencies.jar
尽管如此,由于某种原因,它还是拾取了错误的罐子人工制品。
我想念什么?如何运作?
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>
答案 0 :(得分:0)
要引用文档,请:
<descriptorRef>artifact-with-dependencies</descriptorRef>
将添加名称为创建的工件 $ {project.build.finalName}。$ {artifact.extension}和所有jar targetDir(默认为/ maven)中的依赖项。
这不是您想要的。
您想要的是自定义程序集,使其类似于:
<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项目构建映像,它可能会更适合您的需求。