下图 3 一定要是 resources下 否则 结果都在运行时报了Error :Invalid or corrupt jarfile xxx.jar错误。
最终 项目下会有 out 文件夹 jar包在里面
进入jar目录
cmd进入命令行
运行 java -jar xxxx.jar 启动
浏览器 http://localhost:port/路径
就能访问了
如果运行jar包报错
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
检查pom文件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.a.aApplication</mainClass> <!-- 指定启动主类 -->
<fork>true</fork> <!-- 如果没有该配置,devtools不会生效 打包 将外部jar包打包进项目中 -->
<includeSystemScope>true</includeSystemScope> <!-- 打包 将外部jar包打包进项目中 -->
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>