create a JAVA Standalone executable application to run on different platforms without any Installation

人盡茶涼 提交于 2020-01-12 07:59:25

问题


I have created a run time image for my Java application using jlink and I would like to be able to ship my app as an executable to different platforms.

Ideally, it would be a single file that a user can double click and start the application without the need for installing anything.

Is there currently a good way to do this?


回答1:


You can make an installer that installs the JDK and the application. Make the application an exe by using something like Launch4j and for a Mac executable follow this tutorial by Oracle: Packaging a Java App for Distribution on a Mac and lastly: For Linux

Minecraft uses this method and as far as that i don't know any other way.

If you want to make portable application, "make once run anywhere" type app then I'd suggest trying out a different programming language like C# which also requires the .NET JVM but is embedded in Windows systems.




回答2:


Double click to run executables on multiple platforms, requires prior registration of the file type with the operating system, or an existing file type to know how to handle the code.

jlink statically links the "required modules and their transitive dependencies" to the output.

There is no cross platform solution to this problem.

It is improbable(or to put it another way, not feasible) to include all platforms in a single file, since each executable type(COFF, ELF...), has a different structure. You could attempt to use a generic batch file to start the proper executable, but on Windows, that would require a text file type encoding; thus poisoning the remaining binary code.

Using jlink and the new jmod file format will allow you store native code in a Java container, and thus allowing the entry point into the embedded native JRE code in a single executable image for a single pre-defined platform.

The other side of this issue is the security implications. Since the embedded JRE is not subject to security updates, crackers may choose to embed a previously known flawed JRE, thus exposing corrected exploits to unknowing consumers.

The expected response from Anti-Virus programs would be to flag all non-updated embedded JRE's as viruses.




回答3:


Also, have a look at SubstrateVM. This is not a true Java, however, it may help you in some cases like simple command line applications.

Substrate VM is a framework that allows ahead-of-time (AOT) compilation of Java applications under closed-world assumption into executable images or shared objects (ELF-64 or 64-bit Mach-O).



来源:https://stackoverflow.com/questions/54372647/create-a-java-standalone-executable-application-to-run-on-different-platforms-wi

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