0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Herokuデプロイ時のエラー】 UnsupportedClassVersionErrorとError R10 (Boot timeout)

Posted at

やろうとしていたこと

JavaとVert.xを使用してWebアプリケーションを開発し、そのアプリケーションをHerokuにデプロイしようとしていました。

発生したエラー

デプロイを試みたところ、Herokuのログに2つのエラーが表示されました。

  1. UnsupportedClassVersionError: your-project-directly/ has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0
  2. Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch

エラーの発生理由

  1. UnsupportedClassVersionErrorは、開発環境で使用しているJavaのバージョンがHeroku上のJavaランタイムのバージョンよりも新しいために発生したようです。具体的には、開発環境でJava 17を使用してコンパイルされたクラスファイルを、Heroku上のJava 8環境で実行しようとしたため、このエラーが発生しました。
  2. Error R10は、Herokuがアプリケーションに対して提供している$PORT環境変数のポートに、アプリケーションが90秒以内にバインドできなかったことを示すエラーです。Herokuでは、この時間制限内にアプリケーションが起動しなければならないという制約があります。

解決方法

  1. UnsupportedClassVersionErrorの解決方法:
    HerokuのJavaランタイム環境を、アプリケーションが要求するJavaバージョンに合わせることで解決しました。Herokuのシステムプロパティ設定ファイルを通じてJavaのバージョンを指定することで実現できます。具体的やり方は、system.properties ファイルをプロジェクトのルートディレクトリに作成し、その中に java.runtime.version=17 のような形式でバージョンを指定します。記述する内容はコレだけです!
  2. Error R10の解決方法:
    アプリケーションが、Herokuが指定するポートにバインドするように修正する必要があります。今回の私のようにJavaとVert.xを使用している場合は、System.getenv("PORT")を使用してポート番号を取得し、そのポートにアプリケーションをバインドすることができます。また、アプリケーションの起動時間が長すぎる場合は、Herokuのダイノを使用する方法もあるようです。

参考記事

  1. Heroku Dev Center - Java Support
  2. Heroku Dev Center - Error R10 (Boot timeout)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?