graal icon indicating copy to clipboard operation
graal copied to clipboard

native-image build failed

Open srchen1987 opened this issue 1 year ago • 6 comments

./native-image --version

native-image 21.0.1 2023-10-17 GraalVM Runtime Environment Oracle GraalVM 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19) Substrate VM Oracle GraalVM 21.0.1+12.1 (build 21.0.1+12, serial gc, compressed references)

Test.java

` public class Test{

public static void main(String[] args){
System.out.println("hello");
}

} `

run ./native-image Test

error message:

Error: Determining image-builder observable modules failed (Exit status 1). Process output: Error occurred during initialization of boot layer java.lang.UnsatisfiedLinkError: 'int sun.nio.fs.UnixNativeDispatcher.init()'

srchen1987 avatar Aug 20 '24 02:08 srchen1987

Hi @srchen1987,

Thank you for reaching out to us. Did you try using the latest version of GraalVM? you can find it here https://github.com/graalvm/graalvm-ce-builds/releases Also if you want to create the native image from a class, you can follow the instructions found in this documentation in the from class section

selhagani avatar Aug 22 '24 12:08 selhagani

Hi @srchen1987,

Thank you for reaching out to us. Did you try using the latest version of GraalVM? you can find it here https://github.com/graalvm/graalvm-ce-builds/releases Also if you want to create the native image from a class, you can follow the instructions found in this documentation in the from class section

Is there a bug in version 21?

srchen1987 avatar Aug 23 '24 05:08 srchen1987

I found an other bug

./native-image --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED --add-opens=java.base/jdk.internal.perf=ALL-UNNAMED --add-opens=java.xml/com.sun.org.apache.xerces.internal.dom=ALL-UNNAMED --add-exports=java.base/jdk.internal.loader=ALL-UNNAMED --add-opens=java.base/jdk.internal.misc=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED -jar xxx.jar

./xxx

Exception in thread "main" java.lang.IllegalAccessError: class com.anywide.dawdler.fatjar.loader.launcher.LaunchedURLClassLoader (in unnamed module @0x2d38eb89) cannot access class jdk.internal.loader.URLClassPath (in module java.base) because module java.base does not export jdk.internal.loader to unnamed module @0x2d38eb89

srchen1987 avatar Aug 23 '24 08:08 srchen1987

Hi @srchen1987,

While there isn't necessarily a bug in version 21.0.1 (2023-10-17), we highly recommend updating to the latest version. This ensures you have all the most recent updates, including potential fixes for any issues or bugs identified in previous versions.

It looks like you're working on building a simple example for Native Image. Could you please let me know which commands you used to create your executable? Also, did you follow the instructions provided in the documentation link I shared earlier?

selhagani avatar Aug 26 '24 13:08 selhagani

@selhagani

Here ...

./native-image --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED --add-opens=java.base/jdk.internal.perf=ALL-UNNAMED --add-opens=java.xml/com.sun.org.apache.xerces.internal.dom=ALL-UNNAMED --add-exports=java.base/jdk.internal.loader=ALL-UNNAMED --add-opens=java.base/jdk.internal.misc=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED -jar xxx.jar

I found an other bug

./native-image --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED --add-opens=java.base/jdk.internal.perf=ALL-UNNAMED --add-opens=java.xml/com.sun.org.apache.xerces.internal.dom=ALL-UNNAMED --add-exports=java.base/jdk.internal.loader=ALL-UNNAMED --add-opens=java.base/jdk.internal.misc=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED -jar xxx.jar

./xxx

Exception in thread "main" java.lang.IllegalAccessError: class com.anywide.dawdler.fatjar.loader.launcher.LaunchedURLClassLoader (in unnamed module @0x2d38eb89) cannot access class jdk.internal.loader.URLClassPath (in module java.base) because module java.base does not export jdk.internal.loader to unnamed module @0x2d38eb89

srchen1987 avatar Aug 27 '24 03:08 srchen1987

I'm afraid I don't understand what you're trying to do here. If your goal is to build the Native Image of a simple java class then just like what is specified in the documentation you can follow these steps.

  1. Create your java class. For example this:
     public static void main(String[] args) {
         System.out.println("Hello, Native World!");
     }
 }
  1. Compile it and build a native executable from the Java class
 javac HelloWorld.java
 native-image HelloWorld
  1. Run the application: ./helloworld

selhagani avatar Aug 28 '24 13:08 selhagani

I'm afraid I don't understand what you're trying to do here. If your goal is to build the Native Image of a simple java class then just like what is specified in the documentation you can follow these steps.

  1. Create your java class. For example this:
     public static void main(String[] args) {
         System.out.println("Hello, Native World!");
     }
 }
  1. Compile it and build a native executable from the Java class
 javac HelloWorld.java
 native-image HelloWorld
  1. Run the application: ./helloworld

A simple example can run. I have tested it before. Please note that I used jpms in my code.

I was added --add-exports=java.base/jdk.internal.loader=ALL-UNNAMED

But run it still reports an error :

Exception in thread "main" java.lang.IllegalAccessError: class com.anywide.dawdler.fatjar.loader.launcher.LaunchedURLClassLoader (in unnamed module @0x2d38eb89) cannot access class jdk.internal.loader.URLClassPath (in module java.base) because module java.base does not export jdk.internal.loader to unnamed module @0x2d38eb89

srchen1987 avatar Aug 29 '24 02:08 srchen1987

I am not able to reproduce the issue with the information you provided. Could you please create a reproducer and push it in a github repo and share it with me? Also make sure to include the steps you followed to reproduce the issue. Thank you.

selhagani avatar Aug 29 '24 13:08 selhagani

Since there hasn’t been any activity for over two weeks, I’ll be closing this issue for now. Thank you for your understanding!

selhagani avatar Sep 23 '24 14:09 selhagani