kusumotolab / kGenProg

A High-performance, High-extensibility and High-portability APR System
MIT License
48 stars 13 forks source link

shadowjarで生成したfatjarが起動できない #773

Closed shinsuke-mat closed 4 years ago

shinsuke-mat commented 4 years ago

shadowjar入れた後からjarが起動できなくなっている.

$ wget https://github.com/kusumotolab/kGenProg/releases/download/v1.7.1/kGenProg-1.7.1-all.jar
$ (cd example/CloseToZero01; java -jar ../../kGenProg-1.7.1-all.jar)
$ # 何も出力せずに終了
shinsuke-mat commented 4 years ago

原因

shadowjarによるnested-jarハンドルの問題. kgpは src/main/resource に改変済みjunitがjarリソースとして設置されている. 実行時にtemp直下に展開してclass-loadingする.

shadowjarはfatjar生成時に「全ての」jar/zipを展開するらしい. https://github.com/johnrengelman/shadow/issues/196 https://github.com/johnrengelman/shadow/issues/111

なのでリソースjar自体が存在せず,classファイルとしてぶちまけられる.

$ jar -tvf kGenProg-1.6.2.jar | grep ' junit[0-9]'
     0 Tue Jun 02 06:43:36 JST 2020 junit3/
120640 Tue Jun 02 06:43:36 JST 2020 junit3/junit-3.8.2.jar
     0 Tue Jun 02 06:43:36 JST 2020 junit4/
316993 Tue Jun 02 06:43:36 JST 2020 junit4/junit-4.12-kgp-custom.jar
$ jar -tvf kGenProg-1.7.1-all.jar | grep ' junit[0-9]'
     0 Thu Jul 16 01:30:10 JST 2020 junit3/
     0 Thu Jul 16 01:30:10 JST 2020 junit4/

$ jar -tvf /d/tmp/kGenProg-1.6.2.jar | grep ' junit' | grep '.class' | wc -l
29
$ jar -tvf /d/tmp/kGenProg-1.7.1-all.jar | grep ' junit' | grep '.class' | wc -l
94

対処

本質的にshadowjarが対応してくれないと無理. 一時策っぽいコード. https://github.com/vert-x3/vertx-starter/commit/27eaa6238fdec8ed13065c84efb6c1aa3cc8f4b2

shadowjarやめるかなあ

YoshikiHigo commented 4 years ago

↑の対策は応急処置感がありますね.美しくない. 一方改変する行数は少ないので,アリと言えばアリな気もします.

shinsuke-mat commented 4 years ago

応急処置無理でした. 基本的に .jar という拡張子を .jarr に変えることでfatjarの展開を避ける, という対策なんですが,そうするとintellijが名前を変えた .jarr をロードできなくなる.

あちらをたてばこちらが立たず.