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

天大地大妈咪最大 提交于 2019-12-10 10:18:07

问题


The spring-boot-maven-plugin main goal is to package spring boot application into executable jar with all dependencies. 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.


回答1:


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).

It is basically Spring's version of the onejar plugin (but it also adds its own shells script to the 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>). The small loader does NOT load up any Springframework code.

Of course your Main class has to know how to start up a servlet container (or whatever you plan on loading). Most servlet containers have documentation on how to run in embedded mode.

As for a code example you would put the following in the <build> section :

        <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. The documentation for the plugin is actually not bad.




回答2:


I guess spring boot maven plugin is meant only for spring project to bring all dependencies in one shot.

If you have a problem with identifying dependencies you can simply create one spring boot project. Once done you will get all the libraries in your spring project. Copy or import those libraries in your project with out spring.

With this approach setup of the project with all dependencies will become easier.



来源:https://stackoverflow.com/questions/42696495/can-spring-boot-maven-plugin-be-used-for-non-spring-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!