"no main manifest attribute, in server.war" 没有使用主 class
"no main manifest attribute, in server.war" not using a main class
我想要做的是 Docker 运行 一个带有 Maven 的 TomEE 8.0.0 应用程序。但是,在编译应用程序时,它给了我标题 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
- Can't execute jar- file: "no main manifest attribute"
我的问题是,因为我没有在应用程序中使用任何“主要”class,但是有 TomEE 运行ning 应用程序,我如何包含 manifest.mf正确吗?
或者,如果不是这种情况,我应该如何启动该应用程序,因为目前我通过执行以下命令 运行 具有 Docker 的应用程序
ENTRYPOINT ["java","-jar","server.war"]
来自java
tool specs
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.
您正在尝试 运行 一个 war,与罐子不同,它不能 运行 独立,但它需要一个容器;在你的情况下 TomEE.
https://github.com/tomitribe/docker-tomee 描述了你应该如何开始 tomee,以及如何将你的 war 添加到图像中。
最终,在对 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 <hogstrom@apache.org>
9056B710F1E332780DE7AF34CBAEBE39A46C4CA1 \
# Jeremy Whitlock <jwhitlock@apache.org>
F067B8140F5DD80E1D3B5D92318242FE9A0B1183 \
# Richard Kenneth McGuire (CODE SIGNING KEY) <rickmcguire@apache.org>
223D3A74B068ECA354DC385CE126833F9CF64915 \
# Jonathan Gallimore <jgallimore@apache.org>
DBCCD103B8B24F86FFAAB025C8BB472CD297D428 \
# Jarek Gawor (CODE SIGNING KEY) <gawor@apache.org>
7A2744A8A9AAF063C23EB7868EBE7DBE8D050EEF \
# Jarek Gawor <gawor@apache.org>
B8B301E6105DF628076BD92C5483E55897ABD9B9 \
# Andy Gumbrecht (TomEE Code Signing) <agumbrecht@tomitribe.com>
FAA603D58B1BA4EDF65896D0ED340E0E6D545F97 \
# Romain Manni-Bucau <rmannibucau@tomitribe.com>
A57DAF81C1B69921F4BA8723A8DE0A4DB863A7C1 \
# Mark Struberg (Apache) <struberg@apache.org>
82D8419BA697F0E7FB85916EE91287822FDB81B1 \
# David Blevins <dblevins@apache.org>
B7574789F5018690043E6DD9C212662E12F3E1DD \
# Xu Hai Hong (Ivan Xu @ Geronimo) <xhhsld@gmail.com>
C23A3F6F595EBD0F960270CC997C8F1A5BE6E4C1 \
# Jean-Louis Monteiro (CODE SIGNING KEY) <jlmonteiro@apache.org>
678F2D98F1FD9643811639FB622B8F2D043F71D8 \
# Romain Manni-Bucau <rmannibucau@apache.org>
BDD0BBEB753192957EFC5F896A62FC8EF17D8FEF \
# Romain Manni-Bucau <rmannibucau@apache.org>
D11DF12CC2CA4894BDE638B967C1227A2678363C \
# Roberto Cortez (Apache Signing Key) <radcortez@yahoo.com>
C92604B0DEC5C62CFF5801E73D4683C24EDC64D1 \
# David Blevins <dblevins@tomitribe.com>
626C542EDA7C113814B77AF09C04914D63645D20 \
# Jean-Louis Monteiro (CODE SIGNING KEY) <jlmonteiro@apache.org>
3948829384B269D333CC5B98358807C52B4B0E23 \
# Richard Zowalla (Code Signing Key) <rzo1@apache.org>
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
这基本上是用 Maven 创建了一个 .war
文件,然后在 tomee 服务器中使用 .war
文件,最后使用 COPY --from=build /workspace/target/*.war /workspace/tomee/webapps/server.war
.[=19= 添加它]
我想要做的是 Docker 运行 一个带有 Maven 的 TomEE 8.0.0 应用程序。但是,在编译应用程序时,它给了我标题 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
- Can't execute jar- file: "no main manifest attribute"
我的问题是,因为我没有在应用程序中使用任何“主要”class,但是有 TomEE 运行ning 应用程序,我如何包含 manifest.mf正确吗?
或者,如果不是这种情况,我应该如何启动该应用程序,因为目前我通过执行以下命令 运行 具有 Docker 的应用程序
ENTRYPOINT ["java","-jar","server.war"]
来自java
tool specs
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.
您正在尝试 运行 一个 war,与罐子不同,它不能 运行 独立,但它需要一个容器;在你的情况下 TomEE.
https://github.com/tomitribe/docker-tomee 描述了你应该如何开始 tomee,以及如何将你的 war 添加到图像中。
最终,在对 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 <hogstrom@apache.org>
9056B710F1E332780DE7AF34CBAEBE39A46C4CA1 \
# Jeremy Whitlock <jwhitlock@apache.org>
F067B8140F5DD80E1D3B5D92318242FE9A0B1183 \
# Richard Kenneth McGuire (CODE SIGNING KEY) <rickmcguire@apache.org>
223D3A74B068ECA354DC385CE126833F9CF64915 \
# Jonathan Gallimore <jgallimore@apache.org>
DBCCD103B8B24F86FFAAB025C8BB472CD297D428 \
# Jarek Gawor (CODE SIGNING KEY) <gawor@apache.org>
7A2744A8A9AAF063C23EB7868EBE7DBE8D050EEF \
# Jarek Gawor <gawor@apache.org>
B8B301E6105DF628076BD92C5483E55897ABD9B9 \
# Andy Gumbrecht (TomEE Code Signing) <agumbrecht@tomitribe.com>
FAA603D58B1BA4EDF65896D0ED340E0E6D545F97 \
# Romain Manni-Bucau <rmannibucau@tomitribe.com>
A57DAF81C1B69921F4BA8723A8DE0A4DB863A7C1 \
# Mark Struberg (Apache) <struberg@apache.org>
82D8419BA697F0E7FB85916EE91287822FDB81B1 \
# David Blevins <dblevins@apache.org>
B7574789F5018690043E6DD9C212662E12F3E1DD \
# Xu Hai Hong (Ivan Xu @ Geronimo) <xhhsld@gmail.com>
C23A3F6F595EBD0F960270CC997C8F1A5BE6E4C1 \
# Jean-Louis Monteiro (CODE SIGNING KEY) <jlmonteiro@apache.org>
678F2D98F1FD9643811639FB622B8F2D043F71D8 \
# Romain Manni-Bucau <rmannibucau@apache.org>
BDD0BBEB753192957EFC5F896A62FC8EF17D8FEF \
# Romain Manni-Bucau <rmannibucau@apache.org>
D11DF12CC2CA4894BDE638B967C1227A2678363C \
# Roberto Cortez (Apache Signing Key) <radcortez@yahoo.com>
C92604B0DEC5C62CFF5801E73D4683C24EDC64D1 \
# David Blevins <dblevins@tomitribe.com>
626C542EDA7C113814B77AF09C04914D63645D20 \
# Jean-Louis Monteiro (CODE SIGNING KEY) <jlmonteiro@apache.org>
3948829384B269D333CC5B98358807C52B4B0E23 \
# Richard Zowalla (Code Signing Key) <rzo1@apache.org>
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
这基本上是用 Maven 创建了一个 .war
文件,然后在 tomee 服务器中使用 .war
文件,最后使用 COPY --from=build /workspace/target/*.war /workspace/tomee/webapps/server.war
.[=19= 添加它]