sbt / sbt-native-packager

sbt Native Packager
https://sbt-native-packager.readthedocs.io/en/stable/
BSD 2-Clause "Simplified" License
1.59k stars 437 forks source link

Native image executable: could not find or load main class #1544

Open tpetillot opened 1 year ago

tpetillot commented 1 year ago

Expected behaviour

graalvm-native-image:packageBin produce an executable, that can be execute from anywhere if exported.

Actual behaviour

graalvm-native-image:packageBin produce an executable, that work properly if started in target/graalvm-native-image. But doesn't If moved anywhere else, or if target/scala-2.13/classes are deleted:

Error: Could not find or load main class io.tpetillot.hellograalvm.Main
Caused by: java.lang.ClassNotFoundException: io.tpetillot.hellograalvm.Main

From my understanding, produced executable include everything needed (with exception for classes access through reflection).

Here i'm running a simple hello world.

As it's my first steps with GraalVM and native images, I'm surely missing something?

Information

tpetillot commented 1 year ago

It work with option --report-unsupported-elements-at-runtime. But I cannot understand why:

-report-unsupported-elements-at-runtime: report the usage of unsupported methods and fields at runtime when they are accessed the first time, instead of an error during an image building.

I did not get an error during image building, but when executing elsewhere than where it was...

--no-fallback also works, but I don't get the underlying reason aswell.