Heroku 无法部署 Java 11 Spring Boot App [英] Heroku cannot deploy Java 11 Spring Boot App
问题描述
我正在尝试使用 Java 版本 11.0.1 在 Heroku 上部署 Spring Boot 应用程序.错误:
无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project my-project: Fatal error compiling: invalid target release: 11 ->[帮助1]
经过大量研究,我找到了
Windows 上的 java 版本也在 11.0.1 上设置
并且在部署时
pom.xml
<modelVersion>4.0.0</modelVersion><groupId>net.manolispapadimitriou</groupId><artifactId>我的项目</artifactId><version>0.0.1-SNAPSHOT</version><包装>罐</包装><name>我的项目</name><description>我的项目</description><父母><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.0.RELEASE</version><relativePath/><!-- 从存储库中查找父级 --></父母><属性><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></属性><依赖项><依赖><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></依赖><依赖><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></依赖><依赖><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-aws</artifactId></依赖><!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP --><依赖><groupId>com.zaxxer</groupId><artifactId>HikariCP</artifactId><version>3.2.0</version></依赖><依赖><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId></依赖><依赖><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>运行时</scope></依赖><依赖><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><范围>测试</范围></依赖><!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc --><依赖><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.1.3.RELEASE</version></依赖><依赖><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><可选>真</可选></依赖><依赖><groupId>com.fasterxml.jackson.datatype</groupId><artifactId>jackson-datatype-jsr310</artifactId></依赖><依赖><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId><version>2.1.0.RELEASE</version></依赖><依赖><groupId>io.jsonwebtoken</groupId><artifactId>jjwt</artifactId><version>0.7.0</version></依赖></依赖项><依赖管理><依赖项><依赖><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><范围>导入</范围></依赖></依赖项></dependencyManagement><构建><插件><插件><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></插件><插件><继承的>真</继承的><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId></插件></插件></build><存储库><存储库><id>spring-milestones</id><name>春季里程碑</name><url>https://repo.spring.io/milestone</url><快照><启用>假</启用></快照></repository></repositories></项目>
通过在项目根文件夹中添加 system.properties
文件,我已经成功地在 heroku 上部署了我的应用程序.
system.properties
java.runtime.version=11
pom.xml
<java.version>11</java.version></属性>
`
<依赖><groupId>org.postgresql</groupId><artifactId>postgresql</artifactId><version>9.4-1206-jdbc42</version></依赖>
参考https://devcenter.heroku.com/articles/java-support#specifying-a-java-version
解决方案有效.
I am trying to deploy a Spring Boot app on Heroku ,using Java version 11.0.1. The error:
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]
After a lot of research, I've found https://github.com/heroku/heroku-buildpack-java . I've created the system.properties
file with multiple variations like :
java.runtime.version=11
java.runtime.version=11.0.1
But still, the same error appears while deploying. Spring Boot and Project java version is set to 11.
And the java version on Windows is set as well on 11.0.1
And while deploying
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>
I have successfully deployed my application on heroku by adding system.properties
file in the project root folder.
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>
Reference https://devcenter.heroku.com/articles/java-support#specifying-a-java-version
The solution is working.
这篇关于Heroku 无法部署 Java 11 Spring Boot App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!