我想要做的是讓 Docker 使用 Maven 運行 TomEE 8.0.0 應用程式。但是,在編譯應用程式時,它給了我來自 title 的錯誤no main manifest attribute, in server.war
。
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>server</artifactId>
<version>0.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>12</maven.compiler.source>
<maven.compiler.target>12</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomee.maven</groupId>
<artifactId>tomee-embedded-maven-plugin</artifactId>
<version>8.0.0</version>
<configuration>
<context>ROOT</context>
<containerProperties>
<tomee.mp.scan>true</tomee.mp.scan>
</containerProperties>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>mp-common</artifactId>
<version>8.0.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</build>
<packaging>war</packaging>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>2.0</version>
<type>pom</type>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.json</groupId>
<artifactId>javax.json.bind-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>2.3.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
我嘗試了以下解決方案但無濟于事
- https://www.javatpoint.com/no-main-manifest-attribute
- http://www.skylit.com/javamethods/faqs/createjar.html
- 無法執行 jar- 檔案:“沒有主要清單屬性”
我的問題是,因為我沒有在應用程式中使用任何“主”類,而是讓 TomEE 運行應用程式,我怎樣才能正確包含 manifest.mf?
或者,如果不是這種情況,我應該如何啟動應用程式,因為目前我通過執行以下命令使用 Docker 運行應用程式
入口點 ["java","-jar","server.war"]
uj5u.com熱心網友回復:
從java
工具規格
The java command starts a Java application. It does this by starting the Java Runtime Environment (JRE), loading the specified class, and calling that class's main() method. The method must be declared public and static, it must not return any value, and it must accept a String array as a parameter. The method declaration has the following form:
public static void main(String[] args)
By default, the first argument that is not an option of the java command is the fully qualified name of the class to be called. If the -jar option is specified, its argument is the name of the JAR file containing class and resource files for the application. The startup class must be indicated by the Main-Class manifest header in its source code.
您正在嘗試進行戰爭,與 jar 不同,它不能獨立運行,但需要容器;在你的情況下,TomEE。
https://github.com/tomitribe/docker-tomee描述了你應該如何啟動 tomee,以及如何將你的戰爭添加到影像中。
uj5u.com熱心網友回復:
最終,在對 Robert Scholte 的提示感到困惑之后,這些提示幫助我尋找解決方案,真正的問題不pom.xml
在于Dockerfile
. 在舊的 Dockerfile 中,我試圖將其.war
作為.jar
檔案運行。
稍微按照https://github.com/tomitribe/docker-tomee的設定,我最終設定了以下 Dockerfile
FROM maven:3.8.3-jdk-11-slim AS build
RUN mkdir -p /workspace
WORKDIR /workspace
COPY pom.xml /workspace
COPY src /workspace/src
RUN mvn -B -f pom.xml clean package -DskipTests
FROM openjdk:11-jdk-slim
RUN apt-get update; apt-get -y install curl gpg
ENV PATH /workspace/tomee/bin:$PATH
RUN mkdir -p /workspace/tomee
WORKDIR /workspace/tomee
RUN set -xe; \
for key in \
# Matt Hogstrom <[email protected]>
9056B710F1E332780DE7AF34CBAEBE39A46C4CA1 \
# Jeremy Whitlock <[email protected]>
F067B8140F5DD80E1D3B5D92318242FE9A0B1183 \
# Richard Kenneth McGuire (CODE SIGNING KEY) <[email protected]>
223D3A74B068ECA354DC385CE126833F9CF64915 \
# Jonathan Gallimore <[email protected]>
DBCCD103B8B24F86FFAAB025C8BB472CD297D428 \
# Jarek Gawor (CODE SIGNING KEY) <[email protected]>
7A2744A8A9AAF063C23EB7868EBE7DBE8D050EEF \
# Jarek Gawor <[email protected]>
B8B301E6105DF628076BD92C5483E55897ABD9B9 \
# Andy Gumbrecht (TomEE Code Signing) <[email protected]>
FAA603D58B1BA4EDF65896D0ED340E0E6D545F97 \
# Romain Manni-Bucau <[email protected]>
A57DAF81C1B69921F4BA8723A8DE0A4DB863A7C1 \
# Mark Struberg (Apache) <[email protected]>
82D8419BA697F0E7FB85916EE91287822FDB81B1 \
# David Blevins <[email protected]>
B7574789F5018690043E6DD9C212662E12F3E1DD \
# Xu Hai Hong (Ivan Xu @ Geronimo) <[email protected]>
C23A3F6F595EBD0F960270CC997C8F1A5BE6E4C1 \
# Jean-Louis Monteiro (CODE SIGNING KEY) <[email protected]>
678F2D98F1FD9643811639FB622B8F2D043F71D8 \
# Romain Manni-Bucau <[email protected]>
BDD0BBEB753192957EFC5F896A62FC8EF17D8FEF \
# Romain Manni-Bucau <[email protected]>
D11DF12CC2CA4894BDE638B967C1227A2678363C \
# Roberto Cortez (Apache Signing Key) <[email protected]>
C92604B0DEC5C62CFF5801E73D4683C24EDC64D1 \
# David Blevins <[email protected]>
626C542EDA7C113814B77AF09C04914D63645D20 \
# Jean-Louis Monteiro (CODE SIGNING KEY) <[email protected]>
3948829384B269D333CC5B98358807C52B4B0E23 \
# Richard Zowalla (Code Signing Key) <[email protected]>
B83D15E72253ED1104EB4FBBDAB472F0E5B8A431 \
; do \
gpg --batch --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys "$key" || \
gpg --batch --keyserver hkp://pgp.mit.edu:80 --recv-keys "$key" ; \
done
ENV TOMEE_VER 8.0.11
ENV TOMEE_BUILD plus
RUN set -x \
&& curl -fSL https://dist.apache.org/repos/dist/release/tomee/tomee-${TOMEE_VER}/apache-tomee-${TOMEE_VER}-${TOMEE_BUILD}.tar.gz.asc -o tomee.tar.gz.asc \
&& curl -fSL https://dist.apache.org/repos/dist/release/tomee/tomee-${TOMEE_VER}/apache-tomee-${TOMEE_VER}-${TOMEE_BUILD}.tar.gz.sha512 -o tomee.tar.gz.sha512 \
&& curl -fSL https://dist.apache.org/repos/dist/release/tomee/tomee-${TOMEE_VER}/apache-tomee-${TOMEE_VER}-${TOMEE_BUILD}.tar.gz -o apache-tomee-${TOMEE_VER}-${TOMEE_BUILD}.tar.gz \
&& gpg --batch --verify tomee.tar.gz.asc apache-tomee-${TOMEE_VER}-${TOMEE_BUILD}.tar.gz \
&& echo `cat tomee.tar.gz.sha512` apache-tomee-${TOMEE_VER}-${TOMEE_BUILD}.tar.gz | sha512sum -c - \
&& tar -zxf apache-tomee-${TOMEE_VER}-${TOMEE_BUILD}.tar.gz \
&& mv apache-tomee-${TOMEE_BUILD}-${TOMEE_VER}/* /workspace/tomee \
&& rm apache-tomee-${TOMEE_VER}-${TOMEE_BUILD}.tar.gz \
&& rm -Rf apache-tomee-${TOMEE_BUILD}-${TOMEE_VER} \
&& rm bin/*.bat \
&& rm bin/*.exe \
&& rm bin/*.tar.gz* \
&& rm tomee.tar.gz.asc \
&& rm tomee.tar.gz*
EXPOSE 8080
CMD ["catalina.sh", "run"]
WORKDIR /workspace
COPY --from=build /workspace/target/*.war /workspace/tomee/webapps/server.war
這基本上.war
用 maven 創建了一個檔案,然后.war
在 tomee 服務器中使用該檔案,最后使用COPY --from=build /workspace/target/*.war /workspace/tomee/webapps/server.war
.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/470041.html
標籤:行家 dockerfile pom.xml 阿帕奇托米
上一篇:如何在Java、JDK17、“module-info.java”、Netbeans、Maven上“要求”模塊“gwt.user”(問題繼續)