我想做的是让 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"
我的问题是,因为我没有在应用程序中使用任何“主”类,但让 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/