This is a HelloWorld Java example, referenced from Getting Started with Native Image.
-
Compile the application running the follow command:
javac -d build src/com/example/HelloWorld.java
This generates the
HelloWorld.class
file intobuild/com/example
directory. -
Run the application from a class file:
java -cp ./build com.example.HelloWorld
It outputs the message "Hello, Native World!".
- Create a JAR for the application, running the follow command:
jar --create --file HelloWorld.jar --main-class com.example.HelloWorld -C build .
- Run the JAR file:
java -jar HelloWorld.jar
-
Create a native executable of a JAR file:
native-image -jar HelloWorld.jar
The executable called
./HelloWorld
will be created in the working directory. -
Execute it:
./HelloWorld