生成的包结构发生了变化(如果提取 uberjar文件)中Spring Boot 2.1.0.RELEASE.
The 1.5.9.发布 jar文件有com
, lib
, META-INF
, and org
目录
2.1.0.发布 has a BOOT-INF
, META-INF
and org
目录
基本上来自2.0.0.发布往后 - 所有类和库都在BOOT-INF
目录。
由于这个原因 - 当你尝试运行 Spring Boot 项目时亚马逊 Lambda- 它说有一个jar未找到,因为它无法读取新的 Spring Boot Uber jar 结构
我的问题:
- 在较新版本的 Spring Boot Maven 插件中,是否可以生成与 1.5.9.RELEASE 版本中相同结构的 uber jar?
我尝试过maven-shade-plugin
- 但这会导致其他问题。任何帮助表示赞赏。
StackOverflow 的参考链接:Spring Boot Maven 插件 - 无 BOOT-INF 目录 https://stackoverflow.com/questions/43124852/spring-boot-maven-plugin-no-boot-inf-directory
这段 Maven 插件 XML 片段对我来说很有效:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>zip-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>${project.artifactId}-${project.version}</finalName>
<descriptors>
<descriptor>src${file.separator}assembly${file.separator}bin.xml</descriptor>
</descriptors>
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>
此外,您还需要一个assembly/bin.xml
文件包含以下内容:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>lambda-package</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<!-- copy runtime dependencies with some exclusions -->
<fileSet>
<directory>${project.build.directory}${file.separator}lib</directory>
<outputDirectory>lib</outputDirectory>
<excludes>
<exclude>tomcat-embed*</exclude>
</excludes>
</fileSet>
<!-- copy all classes -->
<fileSet>
<directory>${project.build.directory}${file.separator}classes</directory>
<includes>
<include>**</include>
</includes>
<outputDirectory>${file.separator}</outputDirectory>
</fileSet>
</fileSets>
</assembly>
请注意,您必须使用生成的.zip
文件而不是.jar
file.
awslabs 提供了将 Spring Boot 2 与 Lambda 结合使用的完整工作示例:https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/springboot2/pet-store https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/springboot2/pet-store
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)