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. C#中的HashSet, HashTable, Dictionary的区别【转】

    HashSet和Python中的Set差不多,都是为逻辑运算准备的,HashSet不允许数据有重复,且存入的时单值不是键值对. HashTable和Dictionary差不多,但是他们的实现方式时不同 ...

  2. c++字符串split 函数实现

    - 经常遇到字符串分割问题,但是相对于c++而言实现比较麻烦,直接遍历一遍也很冗余 - 另外也适用于,在字符串中找到某个字符的所有位置 //函数功能:将输入字符串s,以字符串c(;)进行拆分,拆分结果 ...

  3. 【Java】Java-XML解析利器-SAX-高性能-易用

    Java-XML解析利器-SAX-高性能-易用 java xml 大_百度搜索 (3)java处理比较大的xml文件 - SegmentFault How to read UTF-8 XML file ...

  4. 如何给USB移动硬盘格式化分区

    硬盘盒装好后,插在电脑USB接口上,电脑正常识别到移动硬盘后,但因为全新硬盘没有分区,在"我的电脑"里是看不到盘符的.下面以40G移动硬盘分区讲一下硬盘如何分区.1.操作系统最好是 ...

  5. VC++ MFC应用程序项目文件

    <?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Bu ...

  6. Android中创建PopupMenu弹出式菜单

    之前写过一篇创建option menu的文章:Android中创建option menu 本文主要是讲如何创建PopupMenu弹出式菜单 1.首先创建menu文件menu2.xml: <?xm ...

  7. Unity3d -> Xcode 多个渠道版本发布文件合并

    第一步: Users/xxx/.jenkins/jobs/projectname/workspace/build/iOS_iphone 把这里面所有文件拷贝到生成的xcode 工程下的Data目录 如 ...

  8. Android 之 应用未捕获异常处理

    最近开发一款低功耗蓝牙通讯的 Android 应用,安装使用时多次出现“ 抱歉,xxx已停止 ”.现在安装Android系统的手机版本和设备千差万别,在模拟器上运行良好的程序安装到某款手机上说不定就出 ...

  9. iSCSI Network Designs: Part 5 – iSCSI Multipathing, Host Bus Adapters, High Availability and Redundancy

    iSCSI Network Designs: Part 5 – iSCSI Multipathing, Host Bus Adapters, High Availability and Redunda ...

  10. Linux中awk命令的简单用法

    一.用例1: cat /proc/meminfo|grep "MemTotal"|awk '{print $2}' 说明,$2表示第2位,$0表示全部,如需表示$,可用$$转义.