1.在pom里添加以下内容,注意spring-boot-maven-plugin插件版本只能是1.4.2.RELEASE
<build><finalName>test</finalName><plugins><!-- 指定编译java版本 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding></configuration></plugin> <!-- mvn jar 打包 --><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>1.4.2.RELEASE</version><configuration><!-- 启动类 --><mainClass>com.xxx.xxxx</mainClass> </configuration><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin><!-- 忽略无web.xml警告 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><configuration><failOnMissingWebXml>false</failOnMissingWebXml></configuration></plugin> </plugins><resources><resource><!-- 包含mybatis映射文件 --><directory>src/main/java</directory><includes><include>**/*.xml</include></includes></resource><resource><directory>${basedir}/src/main/webapp</directory><!-- 注意此次必须要放在此目录下才能被访问到 --><targetPath>META-INF/resources</targetPath> <includes><include>**/**</include></includes></resource><resource><directory>${basedir}/src/main/resources</directory><includes><include>**/**</include></includes><filtering>false</filtering> </resource></resources></build>
2.不可缺少的jar包依赖文件
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-jasper</artifactId>
</dependency>
打完jar包后在启动jar包时报如下错误:请看看pom文件中有没有servlet-api(如下依赖文件)的jar包,如果有请删除掉,然后在打jar包就可以访问到jsp页面了
<!--<dependency>--><!--<groupId>javax.servlet</groupId>--><!--<artifactId>javax.servlet-api</artifactId>--><!--<version>3.1.0</version>--><!--<scope>compile</scope>--><!--</dependency>-->