【发布时间】:2018-09-10 10:35:49
【问题描述】:
我正在使用spring-boot-maven-plugin 来打包我的 REST 服务。我正在使用mvn clean install 或mvn clean package 构建罐子。在我反编译 jar 之后,我没有找到任何添加的依赖项(我原以为它是一个包含所有依赖项的胖 jar)
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.9.RELEASE</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>repackage</goal>
<goal>build-info</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>true</executable>
<finalName>myapp</finalName>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
当我使用 java -jar myapp.jar -Drun.jvmArguments="-Dspring.profiles.active=qal" 运行 spring boot 时,我得到了许多类的 ClassNotFoundException。很明显,artifact 没有按预期构建。但是,如果我使用 maven ./mvnw spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=qal" 启动 Spring Boot 应用程序,我猜它会在目标文件夹中找到所有依赖项,因此可以正常工作。如何解决构建问题,以便我可以使用 java -jar 命令启动应用程序。
编辑:这是一个多模块的 maven 项目
【问题讨论】:
-
从截图来看,重新打包的jar有很多问题。截图出自哪里?另外,像
jar和unzip这样的命令行工具会为jar 的内容显示什么? -
我使用JD-GUI (jd.benow.ca) 解压jar,截图是使用jd-gui解压后的
-
jar 和 unzip 等命令行工具对 jar 的内容显示什么?
-
Jars 只是带有清单的 zip 文件,因此您可以使用 unzip 来查看内容。即 unzip -l 将显示内容。如果您知道列表中的路径,您也可以仔细阅读内容。即这将打印清单: unzip -p target/scila-adapter-service.jar META-INF/MANIFEST.MF
标签: java maven spring-boot spring-boot-maven-plugin