我有要在docker中运行的Java应用,这是我的Dockerfile
FROM openjdk:8-jdk-alpine
RUN apk add --no-cache curl tar bash procps
ARG MAVEN_VERSION=3.5.4
ARG USER_HOME_DIR="/root"
ARG SHA=ce50b1c91364cb77efe3776f756a6d92b76d9038b0a0782f7d53acf1e997a14d
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries
RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
&& curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
&& echo "${SHA} /tmp/apache-maven.tar.gz" | sha256sum -c - \
&& tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
&& rm -f /tmp/apache-maven.tar.gz \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"
COPY docker/entrypoint.sh /usr/local/bin/mvn-entrypoint.sh
COPY docker/settings-docker.xml /usr/share/maven/ref/
RUN mkdir --parents /usr/src/app
WORKDIR /usr/src/app
# Add pom.xml file first only
ADD pom.xml /usr/src/app/
# Perform clean, this way maven will download all dependancies
# and will include them inside image, saving time while running image
# not having to download project`s dependancies every single time
RUN mvn verify clean --fail-never
# Add everything else from the project
# with exception to pom.xml that was already added
ADD src /usr/src/app/src/
ADD resources /usr/src/app/resources/
ENTRYPOINT ["sh", "/usr/local/bin/mvn-entrypoint.sh"]
我的 mvn-entrypoint.sh
#!/bin/bash
mvn package exec:java
exec "$@"
我的项目pom的一部分:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
现在,如果我使用命令在本地运行它,它将正常工作
mvn package exec:java
然后我可以看到我的Main类按预期运行,但是当我构建并运行此映像时,出现以下错误:
[ERROR] Could not find goal 'java
banyard.automation-reporting_1 |
[ERROR] ' in plugin org.codehaus.mojo:exec-maven-plugin:1.6.0 among available goals exec, help, java -> [Help 1]
我真的不知道如何解决,因为我确实在上面的pom中指定了“ java”目标。