Error executing . JAR "no main manifest attribute in nutriclinweb-api.jar"

Asked

Viewed 4,265 times

0

I am using intellij (Spring project), I have taken the right steps to generate . jar, I have tried it in many ways. Follow 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>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>br.unifil.dc</groupId>
<artifactId>nutriclinweb-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>nutriclinweb-api</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- mysql -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

    <!-- Migracoes - Flyway -->
    <dependency>
        <groupId>org.flywaydb</groupId>
        <artifactId>flyway-core</artifactId>
    </dependency>

    <!-- Hibernate Java 8 Support -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-java8</artifactId>
    </dependency>

    <!-- Suporte do Jackson para as datas do Java 8 -->
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jsr310</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.4</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>br.unifil.dc.nutriclinwebapi.NutriclinwebApiApplication</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

  • Your Nutriclinwebapiapplication class has the @Springbootapplication annotation ?

  • Yes, has....

2 answers

3

You are mixing plugins to generate your JAR, you should use only the Spring Boot plugin to generate the executable.

Executable JAR generation occurs through execution repackage:

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <version>2.1.6.RELEASE</version>
  <configuration>
    <mainClass>br.unifil.dc.nutriclinwebapi.NutriclinwebApiApplication</mainClass>
    <layout>JAR</layout>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>repackage</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Remove your plugin maven-jar-plugin, the generation must be realized through the spring-boot-maven-plugin only.

If you unzip the Spring Boot JAR you will see that its structure is completely different from a normal JAR, so there should be this care.

More plugin configuration information can be found on documentation

  • I made the changes, generated the jar again and continues with the same error.

0

I ran the mvn package command at the project root and . jar was generated in target/name-of-your-project-1.0-SNAPSHOT.jar

Browser other questions tagged

You are not signed in. Login or sign up in order to post.