Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling java source code to native exe

Is it possible to compile java source code into native exe like C++? Like C++ all headers files are included during compilation, all java library files that are required should be attached in that exe, and this exe should not be a bytecode but native exe instead and run without jvm.

So all I want to know is something like.. if I can replace all C++ syntax with Java syntax and compile to an exe file like one created by C++ compiler which run directly.

Note: I am not talking about packers that wraps java classes in exe and ultimately requires jvm.

like image 922
Kashyap Kansara Avatar asked Jan 31 '15 08:01

Kashyap Kansara


People also ask

Can Java be compiled to EXE?

Using GraalVM Java applications can be compiled into native standalone executables (will be demonstrated). Native executables of small Java programs startup blazingly fast, use considerably less resources compared to running on JVM and do not even require the JRE or any other kind of runtime apart from the OS.

Can you compile Java to native?

Yes! Native Image The native image feature with the GraalVM SDK helps improve the startup time of Java applications and gives them a smaller footprint. Effectively, it's converting bytecode that runs on the JVM (on any platform) to native code for a specific OS/platform — which is where the performance comes from.


1 Answers

As of 2020-05 the current options include:

  • javapackager (in openFX, add slimmed down JRE to executable)
  • launch4J (35kb external dependency, option to check for and download or include JRE)
  • GraalVM native image for real slim executables (but a bit more configuration for use of reflection)
like image 107
Alim Özdemir Avatar answered Oct 22 '22 03:10

Alim Özdemir