> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/ix.-how-to-guides/86.-build/86.5-use-a-spring-boot-application-as-a-dependency.md).

# 86.5 将Spring Boot应用作为依赖

跟war包一样，Spring Boot应用不是用来作为依赖的。如果你的应用包含需要跟其他项目共享的类，最好的方式是将代码放到单独的模块，然后其他项目及你的应用都可以依赖该模块。

如果不能按照上述推荐的方式重新组织代码，你需要配置Spring Boot的Maven和Gradle插件去产生一个单独的artifact，以适合于作为依赖。可执行存档不能用于依赖，因为[可执行jar格式](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#executable-jar-jar-file-structure)将应用class打包到`BOOT-INF/classes`，也就意味着可执行jar用于依赖时会找不到。

为了产生两个artifacts（一个用于依赖，一个用于可执行jar），你需要指定classifier。classifier用于可执行存档的name，默认存档用于依赖。

可以使用以下配置Maven中classifier的`exec`：

```markup
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <classifier>exec</classifier>
            </configuration>
        </plugin>
    </plugins>
</build>
```
