简体   繁体   English

spring-boot-maven-plugin可用于非弹簧项目吗?

[英]Can spring-boot-maven-plugin be used for non spring project?

The spring-boot-maven-plugin main goal is to package spring boot application into executable jar with all dependencies. spring-boot-maven-plugin主要目标是将spring boot应用程序打包到具有所有依赖项的可执行jar中。 Can it be used in projects without spring or spring boot? 它可以用于没有弹簧或弹簧靴的项目吗? I meen not using spring dependencies, but just classloader mechanism for loading depended jars. 我不是使用spring依赖项,而只是用于加载依赖jar的类加载器机制。

Yes you can! 是的你可以! Actually I tested and I was happy to find the spring-boot-maven-plugin repackage is completely agnostic of what the Main class uses and is for the most part completely decoupled from the Springframework (its unfortunate the documentation doesn't mention this but I guess Spring really wants use their stuff). 实际上我测试过,我很高兴地发现spring-boot-maven-plugin repackage完全不知道Main类使用的是什么,并且大部分与Springframework完全脱钩(不幸的是文档没有提到这个但是我猜泉真的想用他们的东西)。

It is basically Spring's version of the onejar plugin (but it also adds its own shells script to the jar). 它基本上是Spring的onejar插件版本(但它也将自己的shell脚本添加到jar中)。

The spring-boot-maven-plugin repackage ( spring-boot:repackage ) essentially creates its own micro container with a small loader that looks for a specific layout (where the jars are located) which is determined by your project packaging (ie <packaging>war</packaging> or <packaging>jar</packaging> ). spring-boot-maven-plugin重新包装( spring-boot:repackage )基本上创建了自己的微型容器,带有一个小型装载器,用于寻找特定的布局(罐子所在的位置),这取决于您的项目包装(即<packaging>war</packaging><packaging>jar</packaging> )。 The small loader does NOT load up any Springframework code . 小型加载器不会加载任何Springframework代码

Of course your Main class has to know how to start up a servlet container (or whatever you plan on loading). 当然,您的Main类必须知道如何启动servlet容器(或者您计划加载的任何内容)。 Most servlet containers have documentation on how to run in embedded mode. 大多数servlet容器都有关于如何在嵌入模式下运行的文档。

As for a code example you would put the following in the <build> section : 至于代码示例,您可以将以下内容放在<build>部分中:

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <executable>true</executable>
                <fork>true</fork>
            </configuration>
        </plugin>

Then you run the build like mvn package spring-boot:repackage . 然后你像mvn package spring-boot:repackage一样运行构建。 The documentation for the plugin is actually not bad. 插件文档实际上并不坏。

I guess spring boot maven plugin is meant only for spring project to bring all dependencies in one shot. 我想spring boot maven插件仅适用于spring项目,可以一次性带来所有依赖项。

If you have a problem with identifying dependencies you can simply create one spring boot project. 如果您在识别依赖项时遇到问题,可以简单地创建一个Spring启动项目。 Once done you will get all the libraries in your spring project. 完成后,您将获得Spring项目中的所有库。 Copy or import those libraries in your project with out spring. 使用spring复制或导入项目中的库。

With this approach setup of the project with all dependencies will become easier. 通过这种方法,所有依赖项的项目设置将变得更加容易。

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

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