SpringBootMaven插件没有将依赖类拉入jar
我对SpringBootMaven插件没有将依赖类拉入jar,spring,maven,spring-boot,spring-boot-maven-plugin,Spring,Maven,Spring Boot,Spring Boot Maven Plugin,我对springbootmaven插件有一个问题,它没有在生成的jar文件中包含依赖类 在中,它声明具有作用域的依赖项将包含在jar文件中,但我无法让它包含它们 我有一个包含两个子模块的项目:model和restServer。在模型模块中,我想使用swagger来基于openApi输入模型对codegen进行编码。生成的类放在jar文件中:model/target/rest-model-0.0.1-SNAPSHOT.jar 在restServer模块中,我有SpringRestControlle
springbootmaven插件有一个问题,它没有在生成的jar文件中包含依赖类
在中,它声明具有作用域的依赖项将包含在jar文件中,但我无法让它包含它们
我有一个包含两个子模块的项目:model
和restServer
。在模型
模块中,我想使用swagger来基于openApi输入模型对codegen进行编码。生成的类放在jar文件中:model/target/rest-model-0.0.1-SNAPSHOT.jar
在restServer
模块中,我有SpringRestController和应用程序java代码,并希望将model
类“拉入”到生成的jar文件中:restServer/target/rest-server-0.0.1-SNAPSHOT.jar
使用SpringBootMaven插件
builder,但它不包括模型
子模块中的任何内容
下面列出了整个项目结构和pom文件
如何让springbootmaven插件
从model
子模块中提取类文件,从而有效地创建一个“胖”的自包含jar
项目结构
project-root/
pom.xml # parent pom
model/
pom.xml
src/main/openApi/model.json
target/
generated-sources/* (package: com.me.rest.model.*)
rest-model-0.0.1-SNAPSHOT.jar
restServer/
pom.xml
src/main/java/com/me/rest/
controller/Controller.java
Application.java
父pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
</parent>
<groupId>com.me</groupId>
<artifactId>rest-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rest</name>
<packaging>pom</packaging>
<description>Swagger codegen for Spring Rest Server sandbox project</description>
<scm>
<connection>scm:git:git@github.com:swagger-api/swagger-codegen.git</connection>
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
<url>https://github.com/swagger-api/swagger-codegen</url>
</scm>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<modules>
<module>model</module>
<module>restServer</module>
</modules>
</project>
依赖项放在重新打包的JAR文件的BOOT-INF\lib\中
此路径将添加到Spring Boot应用程序的类路径中。依赖项放在Boot-INF\lib\n您是否检查了JAR中的此文件夹?@SimonMartinelli哇,看起来它确实在那里!我在寻找类结构“com/me/rest/…”。使用“jartf”,我看到BOOT-INF/lib/rest-model-0.0.1-SNAPSHOT.jar。我猜jar中的其他类可以使用它,对吗?是的,我添加了这个作为答案。感谢您接受此答案。我添加了清单的更新。我应该在那里看到路径,还是在内部处理它?不,因为Spring Boot有自己的类加载器
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.kontron</groupId>
<artifactId>rest-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.kontron</groupId>
<artifactId>rest-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies> ... </dependencies>
<build>
<plugins>
<!-- Swagger codegen plugin -->
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration> ... </configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.kontron</groupId>
<artifactId>rest-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>rest-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.kontron</groupId>
<artifactId>rest-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope> <!-- Notice scope is provided -->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.1.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Manifest-Version: 1.0
Implementation-Title: rest-server
Implementation-Version: 0.0.1-SNAPSHOT
Built-By: bjohnson
Implementation-Vendor-Id: com.me
Spring-Boot-Version: 2.1.2.RELEASE
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.me.rest.Application
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Created-By: Apache Maven 3.5.4
Build-Jdk: 1.8.0_144
Implementation-URL: https://projects.spring.io/spring-boot/#/spring-bo
ot-starter-parent/rest-parent/rest-server