Heroku 无法部署 Java 11 Spring Boot App [重复]
Posted
技术标签:
【中文标题】Heroku 无法部署 Java 11 Spring Boot App [重复]【英文标题】:Heroku cannot deploy Java 11 Spring Boot App [duplicate] 【发布时间】:2019-05-05 08:36:14 【问题描述】:我正在尝试使用 Java 版本 11.0.1 在 Heroku 上部署 Spring Boot 应用程序。 错误:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project my-project: Fatal error compiling: invalid target release: 11 -> [Help 1]
经过大量研究,我找到了https://github.com/heroku/heroku-buildpack-java。我创建了具有多种变体的system.properties
文件,例如:
java.runtime.version=11
java.runtime.version=11.0.1
但是,部署时仍然出现相同的错误。 Spring Boot 和 Project java 版本设置为 11。
Windows 上的 java 版本也设置为 11.0.1
在部署时
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>
<groupId>net.manolispapadimitriou</groupId>
<artifactId>my-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>my-project</name>
<description>My Project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<spring-cloud.version>Greenwich.M3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>$spring-cloud.version</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
【问题讨论】:
您是否尝试过在设置 -> 构建、执行、部署 -> 编译器 -> Java 编译器中检查目标字节码版本? @4dc0 也是11 能否将您的 pom.xml 添加到问题正文中? 立即添加 您的system.properties
文件是否已添加到 Git 中?您可以通过git ls-files
查看。
【参考方案1】:
通过在项目根文件夹中添加system.properties
文件,我已成功在heroku 上部署了我的应用程序。
system.properties
java.runtime.version=11
pom.xml
<version>2.1.7.RELEASE</version>
<properties>
<java.version>11</java.version>
</properties>
`
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1206-jdbc42</version>
</dependency>
参考 https://devcenter.heroku.com/articles/java-support#specifying-a-java-version
解决方案有效。
【讨论】:
@Muhammad_Shah 你救了我的氏族!这对我来说是救命的人!你来自天堂!以上是关于Heroku 无法部署 Java 11 Spring Boot App [重复]的主要内容,如果未能解决你的问题,请参考以下文章
Heroku部署后Django(djongo)无法连接到MondoDB Atlas
Heroku Discord Bot 构建但在部署时无法工作