本文主要是介绍SpringBoot Web项目打可执行jar包步骤 支持运行JSP,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
spring boot 打jar pom配置如下:注意spring-boot-maven-plugin 版本问题
1、pom添加依赖
<!-- servlet依赖. -->
<dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><scope>provided</scope>
</dependency>
<dependency><groupId>javax.servlet</groupId><artifactId>jstl</artifactId>
</dependency><!-- tomcat的支持.-->
<dependency><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-jasper</artifactId><scope>provided</scope>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId>
</dependency><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><!--目前只能使用1.4.2版本,使用其他版本jsp无法显示--><version>1.4.2.RELEASE</version><configuration><fork>true</fork><!-- spring-boot:run 中文乱码解决 --><jvmArguments>-Dfile.encoding=UTF-8</jvmArguments><!—启动主类 --><mainClass>com.example.demo.DemoApplication</mainClass></configuration><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><configuration><failOnMissingWebXml>false</failOnMissingWebXml></configuration></plugin></plugins><resources><!-- 打包时将jsp文件拷贝到META-INF目录下--><resource><!-- 指定resources插件处理哪个目录下的资源文件 --><directory>src/main/webapp</directory><!--注意此次必须要放在此目录下才能被访问到--><targetPath>META-INF/resources</targetPath><includes><include>**/**</include></includes></resource><resource><directory>src/main/resources</directory><includes><include>**/**</include></includes><filtering>false</filtering></resource><resource><directory>src/main/java</directory><excludes><exclude>**/*.java</exclude></excludes></resource></resources>
</build>
2、添加项目打包配置
3、取个名字,Command line上填写clean package
4、调出Maven Projects界面
5、双击Run Configurations下面刚添加进入的demo[package]
6、target目录下生成jar
7、执行java -jar XXXXX.jar
这篇关于SpringBoot Web项目打可执行jar包步骤 支持运行JSP的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!