如何让swagger-maven-plugin将swagger.json同时写入target/classes适配Eclipse
解决方案:自动复制swagger.json到target/classes
直接通过Maven的maven-resources-plugin实现自动复制,无需额外插件,配置如下:
在pom.xml的<build><plugins>节点中添加以下配置(保留原有swagger-maven-plugin配置):
<plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.3.1</version> <executions> <execution> <id>copy-swagger-json</id> <phase>compile</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.outputDirectory}</outputDirectory> <resources> <resource> <directory>${project.build.outputDirectory}/META-INF/resources/<servicename>/swagger</directory> <includes> <include>swagger.json</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin>
注意事项
- 将配置中的
<servicename>替换为你的实际服务名称 - 该配置绑定到
compile阶段,会在swagger-maven-plugin生成swagger.json后,自动将文件复制到target/classes目录 - 在Eclipse中执行
Maven > Update Project后,直接通过「Run As」→「Spring Boot」运行即可正常加载Swagger文档
内容的提问来源于stack exchange,提问作者David M. Karr
相关产品推荐
相关产品推荐

