Compiling java source code to native exe

"GCJ is a portable, optimizing, ahead-of-time compiler for the Java Programming Language. It can compile Java source code to Java bytecode (class files) or directly to native machine code, and Java bytecode to native machine code."

see: https://gcc.gnu.org/java/


The only to-native-code Java compiler that I'm aware of is The GNU Compiler for the Javatm Programming Language.

But it's extremely unlikely you really need a to-native-code compiler. Packers like the ones you've dismissed can make your program entirely self contained, including installing a private JVM, seamlessly. I strongly recommend you check out the options in this question and its 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)