springBoot打成jar包,在黑窗口运行

Springboot项目打成Jar包Pom配置


2018年02月09日 10:39:56 阅读数:585 标签: springboot jar  更多 
个人分类: JAVA  


版权声明:本文为博主原创文章,转载请标明出处: https://blog.csdn.net/u012343297/article/details/79296065 

<groupId>com.kpatch</groupId>
<artifactId>KpatchExec</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>1
2
3
4

<build>
      <plugins>
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
         </plugin>
         <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.kpatch.KpatchApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>

            </plugin> 
      </plugins>
    </build>

这种jar包不需要部署到tomcat上,直接 java -jar XXX.jar就可以执行程序

第二种需要部署到tomcat上。就是war包的形式

  • 一、修改pom.xml文件将默认的jar方式改为war:
    在这里插入图片描述
    二、排除内置的Tomcat容器(两种方式都可):

在这里插入图片描述
三、继承org.springframework.boot.web.servlet.support.SpringBootServletInitializer,实现configure方法:

为什么继承该类,SpringBootServletInitializer源码注释:

Note that a WebApplicationInitializer is only needed if you are building a war file and deploying it.

If you prefer to run an embedded web server then you won’t need this at all.

注意,如果您正在构建WAR文件并部署它,则需要WebApplicationInitializer。

如果你喜欢运行一个嵌入式Web服务器,那么你根本不需要这个
在这里插入图片描述

2.方式二,新增加一个类继承SpringBootServletInitializer实现configure:
在这里插入图片描述

注意事项:

使用外部Tomcat部署访问的时候,application.properties(或者application.yml)中配置的

server.port=

server.servlet.context-path=

将失效,请使用tomcat的端口,tomcat,webapps下项目名进行访问。

为了防止应用上下文所导致的项目访问资源加载不到的问题,

建议pom.xml文件中标签下添加标签:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值