在原来的pom文件里面注释掉打包的代码 加入如下代码

<plugins>
    <!-- 指定启动类,将依赖打成外部jar包 -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
            <archive>
                <!-- 生成的jar中,不要包含pom.xml和pom.properties这两个文件 -->
                <addMavenDescriptor>false</addMavenDescriptor>
                <manifest>
                    <!-- 是否要把第三方jar加入到类构建路径 -->
                    <addClasspath>true</addClasspath>
                    <!-- 外部依赖jar包的最终位置 -->
                    <classpathPrefix>lib/</classpathPrefix>
                    <!-- 项目启动类 -->
                    <mainClass>com.example.hanggedemo.HanggeDemoApplication</mainClass>
                </manifest>
            </archive>
        </configuration>
    </plugin>
    <!--拷贝依赖到jar外面的lib目录-->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <id>copy-lib</id>
                <phase>package</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <outputDirectory>target/lib</outputDirectory>
                    <excludeTransitive>false</excludeTransitive>
                    <stripVersion>false</stripVersion>
                    <includeScope>runtime</includeScope>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>