简体   繁体   English

部署弹簧靴胖子

[英]Deploying spring boot fat jar

I have a spring boot app which works well in production environment, however lately I have some question marks about fat jar deployment strategy.Total size of the fat jar is about 80 MB and since it all bundled as single jar, every time even I change a single line ,this 80 MB package is redeployed. 我有一个春季启动应用程序,可以在生产环境中很好地工作,但是最近我对胖子罐的部署策略有一些疑问。胖子罐的总大小约为80 MB,并且由于它们都捆绑成一个罐子,所以每次我更换时一行,就重新部署了这个80 MB的程序包。 How can I divide this fat jar in to a main jar and other jars(which are not developed by me) in /lib directory. 如何在/ lib目录中将此胖jar分为一个主jar和其他jar(不是我开发的)。 What choices do I have ? 我有什么选择?

You have a few options, simplest way ( and suggested by official docs ) is to just extract the fat jar file. 您有几种选择,最简单的方法( 并由官方文档建议 )是仅提取胖子jar文件。

$ unzip -q myapp.jar
$ java org.springframework.boot.loader.JarLauncher

There are a couple of issues with this, first of all your application code will now be a bunch of class files(not in it's own jar). 这样做有两个问题,首先,您的应用程序代码现在将是一堆类文件(不在其自己的jar中)。
The second issue is that you are still using the spring-boot loader, which isn't providing as much utility anymore and also pollutes the filesystem. 第二个问题是您仍在使用spring-boot加载程序,该加载程序不再提供太多实用程序,而且还会污染文件系统。

The other option is to change your build to provide you what you want. 另一种选择是更改构建以提供所需的内容。
With gradle you can use the application plugin , with maven, I would recommend the appassembler plugin . 使用gradle可以使用应用程序插件 ,对于maven,我建议使用appassembler插件

Appassembler produces the directory target/appassembler/ which contains a bin directory with a start-script, and a repo directory with all of your dependencies. Appassembler生成目录target/appassembler/ ,其中包含带有开始脚本的bin目录和具有所有依赖项的repo目录。

To use it, you need to disable the spring-boot:repackage task, and tell the appassembler plugin what your main class is. 要使用它,您需要禁用spring-boot:repackage任务,并告诉appassembler插件您的主类是什么。

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>appassembler-maven-plugin</artifactId>
            <version>1.10</version>
            <configuration>
                <programs>
                    <program>
                        <mainClass>com.example.MyMainClass</mainClass>
                        <id>myappname</id>
                    </program>
                </programs>
            </configuration>
        </plugin>
    </plugins>
</build>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM