Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
81 views
in Technique[技术] by (71.8m points)

How To Build Java Native Executable Files For Linux

I'm looking for a way to build my Java or JavaFx apps so that I have a single executable file that runs without installing a Java runtime on the target system that is running Linux (like a .exe on Windows)

Usually, Java apps are packaged into jar files that can be run like this

java -jar <file-name>.jar

This requires us to install a Java JRE beforehand.

I'm looking for a solution to package my Java app so that it can execute without needing a Java JRE on the target machine.

question from:https://stackoverflow.com/questions/65851854/how-to-build-java-native-executable-files-for-linux

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use GraalVM to compile Java apps to native platform executables.

First install GraalVM following steps here: https://www.graalvm.org/docs/getting-started/#install-graalvm

Install the native-image plugin: gu install native-image

Compile your Java app with javac as normal: javac YourApp.java

Compile to a native executable: native-image YourApp

Execute your native executable: ./YourApp


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...