1、pom.xml配置
(1)、jsp需要的jar
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
(2)、插件和静态资源
<build>
<resources>
//必须要有,否则读取不到配置文件,获取不到jsp的相关配置
<resource>
<directory>src/main/resources</directory>
</resource>
//必须要有,否则否则没有jsp、js、css文件资源
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.2.RELEASE</version>
<!-- 必须制定插件版本 -->
</plugin>
</plugins>
</build>
2、配置文件application.yml
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/test
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp
web:
resources:
static-locations: /WEB-INF/
3、项目结构
4、MyEclipse打jar包,找到项目的地址,pom.xml文件所在的目录
运行 mvn clean package
jar在target下面
注意:打包是不要有进程把target目录占用了,否则打包不成功
2、启动jar
提示:
如果系统jdk环境和jar所需要的jdk版本不一致,需要手动设置环境变量(只用于当前项目,系统环境变量没有改变)
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_171 //自己jdk目录
set CLASSPATH=.;%JAVA_HOME%\\lib\\dt.jar;%JAVA_HOMe%\\lib\\tools.jar
set Path=%JAVA_HOME%\\bin
java -jar ***.jar //自己jar地址
3、访问jsp页面 http://localhost:8081/