问题
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.
回答1:
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.
回答2:
"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/
回答3:
I tried Excelsior JET recently and it worked really well for compiling JAR
s into native Windows binaries. The JetpackII
utility allows you to deploy your application on a target machine without needing a Java installation. It may be a bit complicated to get used to but overall a brilliant choice.
来源:https://stackoverflow.com/questions/28249838/compiling-java-source-code-to-native-exe