idea2020 java-Jar file cannot be executed: "no main manifest attribute" solution

idea2020 java-Jar file cannot be executed: "no main manifest attribute" solution

Preface

After writing a jar package and preparing to deploy it to the Alibaba Cloud server, the problem occurred when java -jar was inaccessible, so I started looking for the problem and solved it.

Positioning problem

First of all, I need to know where the problem is, and then I know how to solve it. At first, I didn’t know where the problem was. I followed the console question "nohup: redirecting stderr to stdout" to find a solution, and then found no Use, the problem is not this; then I saw that it executed the java -jar command, because it generated a log file, open the log file "no main manifest attribute", did not find the main class, and then opened the file in the figure below, and found There is no main class, so I know that the problem lies in the packaged jar file.
Insert picture description here

Solution

First of all, my springboot is version 2.4.1, and then the jar package cannot be packaged. I just hit the jar package according to the online method, and the problem just appeared. So my solution is:

1. Switch to version 2.3.5 of springboot

    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

2. Configure the maven plugin,
comment out the configuration

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
<!--                <configuration>-->
<!--                    <skip>true</skip>-->
<!--                </configuration>-->
            </plugin>

Then you can see: The
Insert picture description here
corresponding main class is configured in MANIFEST.MF.
Insert picture description here
Run the java -jar command on the Alibaba Cloud server again, and the project runs successfully!

Guess you like

Origin blog.csdn.net/weixin_43520670/article/details/112701897