75

When running my jar file: java -jar target/places-1.0-SNAPSHOT.jar

I'm getting the next error :

no main manifest attribute, in target/places-1.0-SNAPSHOT.jar

The pom.xml contains the spring-boot-maven-plugin:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <mainClass>com.places.Main</mainClass>
    </configuration>
</plugin>

I also tried to create a MANIFEST.MF file and specifying the class, but it didnt help.

In addition, I also tried:

<properties>
      <!-- The main class to start by executing "java -jar" -->
      <start-class>com.places.Main</start-class>
</properties>

Main class:

@SpringBootApplication
public class Main {
    public static void main(String[] args) throws InterruptedException {
        SpringApplication.run(Main.class,args);
    }
}

Any idea what else can I try?

ℛɑƒæĿᴿᴹᴿ
  • 4,983
  • 4
  • 38
  • 58
JeyJ
  • 3,582
  • 4
  • 35
  • 83

8 Answers8

126

Try adding repackage goal to execution goals.

Otherwise you would need to call the plugin explicitly as mvn package spring-boot:repackage.

With the goal added, you have to call only mvn package.

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <mainClass>com.places.Main</mainClass>
    </configuration>

    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>
ℛɑƒæĿᴿᴹᴿ
  • 4,983
  • 4
  • 38
  • 58
Matej
  • 6,004
  • 2
  • 28
  • 27
  • 3
    It helped ! Can you explain why I need to package it ? – JeyJ Feb 25 '19 at 14:02
  • 11
    If you have `spring-boot-starter-parent` in you pom, you don't need to define `repackage` goal in the plugin. Official doc: https://docs.spring.io/spring-boot/docs/2.3.0.RELEASE/maven-plugin/reference/html/#repackage – Bandham Manikanta Jun 17 '20 at 17:42
  • 3
    The reason for this is that you are no using spring as parent I assume you have it set on dependencyManagement, then you have to explicit define which goal to be hooked for spring-boot-maven-plugin ir order to get an executable jar file. In this case repackage. – Kevin Valdez Jul 02 '20 at 04:11
  • similar issue with multi module: https://stackoverflow.com/questions/70833195/spring-boot-multi-module-spring-boot-maven-plugin-compilation-failure – emoleumassi Jan 24 '22 at 13:37
46

During the Maven package lifecycle phase, the jar archive is enhanced by Spring Boot Maven Plugin and the original jar file (that should have been built using the standard maven-jar-plugin) is replaced with an enhanced executable jar.

Hence you have either to issue the spring-boot:repackage goal yourself when building your module:

mvn package spring-boot:repackage

Or add the goal explicitly within the plugin configuration:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <mainClass>com.places.Main</mainClass>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

You can find more details about the Spring Boot Maven Plugin repackage goal within the official documentation.

tmarwen
  • 15,750
  • 5
  • 43
  • 62
  • https://github.com/ajeetkumarv/healthlog I tried both repackage and plugin but did not work. main method is in application module – Ajeetkumar Sep 23 '20 at 11:19
  • Hi @Ajeetkumar, could you report a new question with your build configuration and point it out. I will be glad to help. – tmarwen Sep 24 '20 at 13:49
24

3 things:
- You have the parent entry in your pom.
- Verify that your plugin is in the build portion of the pom.
- You have a class with the @SpringBootApplicaion annotation.

pom.xml:

...  
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.8.RELEASE</version>
  </parent>

   <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
...

And a class that looks something like this:

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}
MattC
  • 5,874
  • 1
  • 47
  • 40
4

You can specify a parent POM e.g. :

<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>2.1.4.RELEASE</version>
</parent>

During the package goal, the repackage goal will be executed and you'll then get an executable jar.

pringi
  • 3,987
  • 5
  • 35
  • 45
laurentJ
  • 41
  • 1
4

Reback your jar or war using the following command:

mvn package spring-boot:repackage

Add the plugin in plugins parent node like below in pom.xml:

<plugin>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-maven-plugin</artifactId>
   <configuration>                   
      <mainClass>com.sify.scdm.solutionconfigurator.ScdmApplication</mainClass>
   </configuration>
   <executions>
      <execution>
      <goals>
         <goal>repackage</goal>
      </goals>
      </execution>
   </executions>
</plugin>
   



        
pringi
  • 3,987
  • 5
  • 35
  • 45
Joe
  • 41
  • 1
3

added build tag in pom.xml as below solved issue for me.

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
0

Add the plugin below.This worked for me

 <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>1.6</version>
      <executions>
           <!-- Run shade goal on package phase -->
           <execution>
                <phase>package</phase>
                <goals>
                     <goal>shade</goal>
                </goals>
                <configuration>
                     <transformers>
                          <!-- add Main-Class to manifest file -->
                          <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                               <mainClass>MainClass</mainClass>
                               <manifestEntries>
                                    <Class-Path>.</Class-Path>
                                </manifestEntries>
                          </transformer>
                          <transformer
                                 implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                 <resource>META-INF/spring.handlers</resource>
                          </transformer>
                          <transformer
                                 implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                 <resource>META-INF/spring.schemas</resource>
                          </transformer>
                     </transformers>
                </configuration>
           </execution>
      </executions>
</plugin>
CasualBen
  • 829
  • 8
  • 22
XXXXX
  • 1
0

Add this in pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>