zoukankan      html  css  js  c++  java
  • springboot项目打包成jar无法访问jsp页面的解决方法

    1,将maven打包插件的版本改为1.4.2

    <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.4.2.RELEASE</version>
    </plugin>
    

    2,配置 < resources>将webapp打包进target/classes 目录,其中< targetPath>META-INF/resources</ targetPath> 指定将webapp打包到target/classes 目录的META-INF/resources 目录下,必须这样配置,否则会出错.

    设置 targetPath 只能是 META-INF/resources。然后用这个版本最好指定一下启动类main函数<mainClass>,写上你项目的启动类,否则当你项目里面存在多个main方法就会报错不知道用哪个。

    <build>
    		<plugins>
    			<plugin>
    				<groupId>org.springframework.boot</groupId>
    				<artifactId>spring-boot-maven-plugin</artifactId>
    				<version>1.4.2.RELEASE</version>
    				<configuration>
                                <mainClass>XXX.XXX.SpringBootWebApplication</mainClass>
                              </configuration>
    				
    			</plugin>
    		</plugins>
    		<!-- 配置 < resources>将webapp打包进target/classes 目录,其中< targetPath>META-INF/resources</ targetPath> 
    		指定将webapp打包到target/classes 目录的META-INF/resources 目录下,必须这样配置,否则会出错 -->
    		<resources>
    		    <resource>
    		      <directory>src/main/webapp</directory>
    		      <targetPath>META-INF/resources</targetPath>
    		    </resource>
    		    <resource>
    		      <directory>src/main/resources</directory>
    		    </resource>
    		 </resources>
    	</build>
    

    3,使用maven install 如果打包完成之后,用cmd命令启动jar包,然后访问该项目

    打开cmd命令后,输入 java -jar xxx.jar (打的jar包所在的地址,可以直接拖过去) 

    如果运行没有报错,就去访问该项目吧! 

     

  • 相关阅读:
    python之enumerate枚举 第二篇(六):enumerate枚举
    git使用学习
    Git安装
    eclipse对项目整理分类
    Java基础学习总结——Java对象的序列化和反序列化
    工作代码实例
    substring与substr
    第一个jave程序-helloworld
    UI自动化
    sikuli实例
  • 原文地址:https://www.cnblogs.com/zhangliang88/p/12795006.html
Copyright © 2011-2022 走看看