Compiling java source code to native exe

痞子三分冷 提交于 2020-01-13 05:11:05

问题


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 JARs 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!