Jar包发布

在项目pom.xml中, 如果继承了Spring Boot的starter parent, 那么默认已经包含打包需要的plugins了, 设置为jar就能直接打包成包含依赖的可执行的jar

    <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<relativePath/> <!-- lookup parent from repository -->
</parent>

如果不使用Spring Boot的starter parent, 那么需要在<build>中添加plugins, 这样也能打包包含依赖的可执行jar

<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>{你的Application入口class}</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

使用内置Tomcat容器

pom.xml配置

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>

使用内置Jetty容器

pom.xml配置

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

在Application入口, 增加启动参数设置, 在Spring Boot 2.0之后, JettyServletWebServerFactory代替了JettyEmbeddedServletContainerFactory.

@Bean
public JettyServletWebServerFactory jettyEmbeddedServletContainerFactory(
@Value("${server.port:9090}") final String port,
@Value("${jetty.threadPool.maxThreads:200}") final String maxThreads,
@Value("${jetty.threadPool.minThreads:8}") final String minThreads,
@Value("${jetty.threadPool.idleTimeout:60000}") final String idleTimeout) {
JettyServletWebServerFactory jettyContainer = new JettyServletWebServerFactory();
jettyContainer.setPort(Integer.valueOf(port));
final QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(Integer.valueOf(maxThreads));
threadPool.setMinThreads(Integer.valueOf(minThreads));
threadPool.setIdleTimeout(Integer.valueOf(idleTimeout)); jettyContainer.setThreadPool(threadPool);
return jettyContainer;
}

这样在命令行中启动时, 可以通过命令行参数进行配置

$ java -jar your-project.jar --server.port=8081 --jetty.threadPool.maxThreads=300

.

.

Spring Boot 使用Jar打包发布, 并使用 Embedded Jetty/Tomcat 容器的更多相关文章

  1. Spring Boot导出jar包发布

    一:事由 现在的项目组开发项目使用的是Spring Boot的技术,开发的时候是直接通过一个入口主函数来启动项目的.如果将项目交给客户,怎样才能正确的发布运行呢?百度了一下有关的知识,大概了解到是通过 ...

  2. Spring boot项目的打包发布

    Eclipse打包发布项目 打包项目 首先需要将项目编译的文件删除,执行[Run As]->[Maven clean] 如果这个时候项目报错,在pom.xml文件中添加以下代码过滤掉单元测试 & ...

  3. 曹工杂谈:Spring boot应用,自己动手用Netty替换底层Tomcat容器

    前言 问:标题说的什么意思? 答:简单说,一个spring boot应用(我这里,版本升到2.1.7.Release了,没什么问题),默认使用了tomcat作为底层容器来接收和处理连接. 我这里,在依 ...

  4. spring boot打jar包发布

    artifactId 是即将打包的包的名称 version 是即将打包的版本号 packaging 是即将打包的格式,这里讲的是jar包 终端输入命令: mvn clean install 然后在ta ...

  5. Spring Boot 集成servlet,发布为可直接运行的war包,方便后续打包为docker镜像。

    背景:Spring Boot 集成servlet,发布为可直接运行的war包,方便后续打包为docker镜像. 原文地址 https://github.com/weibaohui/springboot ...

  6. spring boot将jar包转换成war包发布

    spring boot将jar包转换成war包发布步骤 将<packaging>jar</packaging>修改为<packaging>war</packa ...

  7. 【Spring Boot学习之八】发布打包

    环境 eclipse 4.7 jdk 1.8 Spring Boot 1.5.2 一.打jar类型1.指定主程序入口,否则运行报错:没有主清单属性pom.xml: <build> < ...

  8. Spring boot 打成jar包问题总结

    Spring boot 打成jar包问题总结 1.Unable to find a single main class from the following candidates 1.1.问题描述 m ...

  9. Spring Boot(十二):spring boot如何测试打包部署

    Spring Boot(十二):spring boot如何测试打包部署 一.开发阶段 1,单元测试 在开发阶段的时候最重要的是单元测试了,springboot对单元测试的支持已经很完善了. (1)在p ...

随机推荐

  1. Java NIO Channel to Channel Transfers

    In Java NIO you can transfer data directly from one channel to another, if one of the channels is a ...

  2. K3C官改固件更新frp客户端

    k3c官改1.2 frpc版本是v0.13,本文介绍如何升级到最新版. 1. 下载最新版frp,发布页:https://github.com/fatedier/frp/releases选择mips版, ...

  3. QT - 内存泄漏检测

    一.安装vld-2.5.1-setup.exe 下载地址:https://archive.codeplex.com/?p=vld 二.pro中添加头文件目录与库目录 INCLUDEPATH += &q ...

  4. go语言之进阶篇主协程先退出

    1.主协程先退出 示例: package main import ( "fmt" "time" ) //主协程退出了,其它子协程也要跟着退出 func main ...

  5. FileStream 的FileShare一点小认识

    C#读写文本文件一般都是用StreamWriter来实现(读书的时候就这样用,毕业后这几年基本也是这样干的),通常代码如下: using (StreamWriter sw = new StreamWr ...

  6. tensorflow_python中文手册

    https://www.tensorflow.org/api_docs/python/tf/nn/static_bidirectional_rnn https://www.w3cschool.cn/t ...

  7. xgboost入门与实战(实战调参篇)

    https://blog.csdn.net/sb19931201/article/details/52577592 xgboost入门与实战(实战调参篇) 前言 前面几篇博文都在学习原理知识,是时候上 ...

  8. THINKPHP 解决模块不存在时出现空页面的问题

    遇到的问题: 最近使用THINKCMF开发了一个企业网站,因为之前客户的域名变更过,然后就发现当某个模块不存在的时候就出现了空页面 在 THINKPHP论坛 上有人说在项目里添加一个EmptyActi ...

  9. 云服务器 ECS Linux Ubuntu 主机修改主机名

    云服务器 ECS Linux 主机修改主机名 修改云服务器 ECS Linux 主机名常见的有两种方式,本文对此进行概要说明. 临时生效修改 使用命令行修改 hostname 主机名(可自定义),重新 ...

  10. 不可不知的Python模块: collections

    原文:http://www.zlovezl.cn/articles/collections-in-python/ Python作为一个“内置电池”的编程语言,标准库里面拥有非常多好用的模块.比如今天想 ...