Spring 当 运行 java -jar 时启动 Elastic Beanstalk java.time.DateTimeException

Spring Boot Elastic Beanstalk java.time.DateTimeException when running java -jar

我有一个 Spring 使用 CodePipeline 在 AWS Elastic Beanstalk 上部署的引导多模块项目。

我的档案: web: java -jar parent/module1/target/y-0.0.1-SNAPSHOT.jar

我的构建文件: build: cd parent && mvn package

我得到的输出是:

Exception in thread "main" java.time.DateTimeException: Invalid value for MonthOfYear (valid values 1 - 12): 0
        at java.time.temporal.ValueRange.checkValidValue(ValueRange.java:311)
        at java.time.temporal.ChronoField.checkValidValue(ChronoField.java:703)
        at java.time.LocalDate.of(LocalDate.java:267)
        at java.time.LocalDateTime.of(LocalDateTime.java:336)
        at org.springframework.boot.loader.jar.CentralDirectoryFileHeader.decodeMsDosFormatDateTime(CentralDirectoryFileHeader.java:127)
        at org.springframework.boot.loader.jar.CentralDirectoryFileHeader.getTime(CentralDirectoryFileHeader.java:116)
        at org.springframework.boot.loader.jar.JarEntry.<init>(JarEntry.java:58)
        at org.springframework.boot.loader.jar.JarFileEntries.getEntry(JarFileEntries.java:316)
        at org.springframework.boot.loader.jar.JarFileEntries.access0(JarFileEntries.java:48)
        at org.springframework.boot.loader.jar.JarFileEntries$EntryIterator.next(JarFileEntries.java:366)
        at org.springframework.boot.loader.jar.JarFileEntries$EntryIterator.next(JarFileEntries.java:350)
        at org.springframework.boot.loader.jar.JarFile.nextElement(JarFile.java:204)
        at org.springframework.boot.loader.jar.JarFile.nextElement(JarFile.java:195)
        at org.springframework.boot.loader.archive.JarFileArchive$EntryIterator.next(JarFileArchive.java:189)
        at org.springframework.boot.loader.archive.JarFileArchive$EntryIterator.next(JarFileArchive.java:174)
        at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchives(JarFileArchive.java:85)
        at org.springframework.boot.loader.ExecutableArchiveLauncher.getClassPathArchives(ExecutableArchiveLauncher.java:69)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)

我去我的 EC2 实例上手动执行 java -jar 命令,它产生了同样的错误。

找说明的时候没找到很多,不过我觉得可能是java版的

openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

EC2 OS:

NAME="Amazon Linux AMI"
VERSION="2018.03"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2018.03"
PRETTY_NAME="Amazon Linux AMI 2018.03"
ANSI_COLOR="0;33"
CPE_NAME="cpe:/o:amazon:linux:2018.03:ga"
HOME_URL="http://aws.amazon.com/amazon-linux-ami/"

编辑:我也发现了这个 - https://github.com/spring-projects/spring-boot/issues/19518

您的 JAR 文件似乎有问题: CentralDirectoryFileHeader 正在读取(ZIP 压缩的)JAR 文件并遇到不正确的日期戳。

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/CentralDirectoryFileHeader.java

编辑:根据 https://github.com/spring-projects/spring-boot/issues/19518,当创建 JAR 的系统的系统时间为 1970 时,就会发生这种情况。

截至今天(2020 年 1 月),错误修复尚未发布。 要解决此问题,您必须在正确设置系统时间后创建一个新的 JAR。