我正在 docker 容器中运行 Maven 项目,出现 Could not find or load main class 错误。
FROM maven:3.6.0-jdk-11-slim AS build
COPY src src
COPY pom.xml .
RUN mvn -f pom.xml clean package install
FROM openjdk:8-jre
COPY --from=build /target /opt/target
WORKDIR /target
RUN ls
CMD ["java", "-jar", "Customer.jar"]
上面的程序集是使用以下插件创建的<build>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.companyname.Customer</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
错误
错误:无法找到或加载主类 com.mycompany.Customer
问题:如何在 docker 中设置 jar 文件的类路径?
编辑
我测试了以下但相同的问题。
CMD ["java", "-cp", "Customer.jar:libs/*", "com.company.customers.Customer"]
错误:无法找到或加载主类 com.company.customers.Customer
jeck猫
相关分类