The springboot project idea can run, but the cmd command line cannot run two kinds of error errors

Project scenario:

After packaging the springboot project with maven, the jar package runs incorrectly on the command line


Problem Description

Error 1:

E:\importantFile\javaProject\dorm_springBootProject\springboot_vue-master-end\demo\springboot\target>java -jar springboot-0.0.1-SNAPSHOT.jar

springboot-0.0.1-SNAPSHOT.jar中没有主清单属性

springboot-0.0.1-SNAPSHOT.jar中没有主清单属性

错误2:

Exception in thread "main" java.lang.ClassNotFoundException: com.springboot.SpringbootApplication
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:46)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)

 java.lang.ClassNotFoundException: com.springboot.SpringbootApplication


Cause Analysis:

Tip: Both problems are unable to find the startup item SpringbootApplication


solution:

Question 1: Two solutions, you can choose one or add both

Solution 1:

Add the following statement under the <biuld><plugins> tag of the pom.xml file,

Pay attention to modifying your own designated entry class (<mainClass> )

         <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!--使用热部署出现中文乱码解决方案-->
                <configuration>
                    <fork>true</fork>
                    <!--增加jvm参数-->
                    <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
                    <!--指定入口类-->
                    <mainClass>com.example.springboot.SpringbootApplication</mainClass>
                </configuration>
            </plugin>

Solution 2:

Add the following statement under the <biuld><plugins> tag of the pom.xml file,

Pay attention to modifying your own designated entry class (<mainClass>)

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

Question 2: The specified entry class (<mainClass>) has not been corrected, please change it again

solve:

Find the <mainClass> tag under pom.xml , and replace the contents with the path of the startup item

 

 

Guess you like

Origin blog.csdn.net/qq_61649579/article/details/127346128