mavendockerfilepom.xmlapache-tomee

"no main manifest attribute, in server.war" not using a main class


What I'm trying to do is have Docker run a TomEE 8.0.0 application with Maven. However when compiling the application, it gives me the error from the 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>

I've tried the following solutions without avail

My question is, because I'm not using any "main" class within the application, but have TomEE running the application, how can I include the manifest.mf correctly?

Or, if this is not the case, how should I start the application, because currently I run the application with Docker through doing the following command

ENTRYPOINT ["java","-jar","server.war"]


Solution

  • Eventually after puzzling around with the hints from Robert Scholte, which helped me in the search of a solution, the indeed problem wasn't so much in the pom.xml, but more so in the setup of the Dockerfile. Within the old Dockerfile I was trying to run the .war as a .jar file.

    Slightly following the setup from https://github.com/tomitribe/docker-tomee I ended up setting up the following 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
    

    This basically creates a .war file with maven and then ends up using that .war file in the tomee server by adding it at the end using COPY --from=build /workspace/target/*.war /workspace/tomee/webapps/server.war.