9
5

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 5 years have passed since last update.

Java 11 で javax.annotation.Generated が見つからない問題

Posted at

課題

gRPC のサンプルコードを Java 11 で動かそうとしたところ、コード生成はうまくいったものの、実行時に下記のようなエラーが出て止まってしまいました。

エラー: シンボルを見つけられません
@javax.annotation.Generated(
                 ^
  シンボル:   クラス Generated
  場所: パッケージ javax.annotation

解決策

grpc/grpc-java のイシュー Java 11: cannot find symbol javax.annotation.Generated #5343 に書かれている通り、Javax Annotation APIを dependencies に追加します。(このイシュー自体は Java9 の条件分岐を入れたら動かなくなったという報告ですが、↓のように条件分岐を入れなければ動きます。)

build.gradle(抜粋)
dependencies {
    implementation 'io.grpc:grpc-netty-shaded:1.23.0'
    implementation 'io.grpc:grpc-protobuf:1.23.0'
    implementation 'io.grpc:grpc-stub:1.23.0'
    compile 'javax.annotation:javax.annotation-api:1.3.2'  // ← この行を追加
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

Javax Annotation API の最新バージョンは Maven Repository でご確認ください。
https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api

9
5
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
9
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?