maven - "no main manifest attribute, in server.war"不使用主类

标签 maven dockerfile pom.xml apache-tomee

我想做的是让 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>

我尝试了以下解决方案,但没有效果

我的问题是,因为我没有在应用程序中使用任何“主”类,但让 TomEE 运行该应用程序,所以如何正确包含 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 ,与 jar 不同,它不能独立运行,但它需要一个容器;就你的情况而言,TomEE。

https://github.com/tomitribe/docker-tomee描述了您应该如何启动 tomee,以及如何将您的 war 添加到图像中。

关于maven - "no main manifest attribute, in server.war"不使用主类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72051183/

相关文章:

maven - 将具有依赖项的特定 Artifact 复制到特定文件夹,将其余依赖项复制到另一个文件夹

docker - LUIS 挂载点

spring - 如何覆盖 Spring Boot 依赖项的默认版本?

java - 如何在子 pom 中使用父 pom 的配置文件属性?

spring - 在tomcat同根路径下部署多个war文件

java - Maven shade - 使用自定义配置重新打包依赖 jar

java - 无法在 Tomcat 7 中运行 maven 项目

java - 在 Java 中无法访问 Maven 依赖项

docker - 在单个 Docker 存储库中存储不同的 Docker 镜像

docker - 将目录路径添加到Docker镜像