问题
Suppose I want to distribute a Java application.
Suppose I want to distribute it as a single executable. I could easily build a .jar with both the application and all its external dependencies in a single file (with some Ant hacking).
Now suppose I want to distribute it as an .exe file on Windows. That\'s easy enough, given the nice tools out there (such as Launch4j and the likes).
But suppose now that I also don\'t want to depend on the end user having the right JRE (or any JRE at all for that matter) installed. I want to distribute a JRE with my app, and my app should run on this JRE. It\'s easy enough to create a Windows installer executable, and embed a folder with all necessary JRE files in it. But then I\'m distributing an installer and not a single-file app.
Is there a way to embed both the application, and a JRE, into an .exe file acting as the application launcher (and not as an installer)?
回答1:
Try to use Avian and ProGuard toolkits. Avian allows to embed lightweight virtual machine in you app. Linux, MacOS, Windows and iOS are supported. And ProGuard allows you to shrink large jar file to prepare to embed.
回答2:
There's a new tool that does this: Packr
https://github.com/libgdx/packr
回答3:
Quite a few options around, commercially this is very good:
http://www.excelsior-usa.com/jet.html
There are two key open source options GCJ and VMKit
http://gcc.gnu.org/java/ and http://vmkit.llvm.org/
Other more prolonged paths would include IKVM.NET:
http://www.ikvm.net/
Which is a .NET JVM which can be statically compiled to an EXE
回答4:
Is there a way to embed both the application, and a JRE, into an .exe file acting as the application launcher (and not as an installer)?
If a commercial tool is ok for you, install4j solves this problem very smoothly (see its "Features" page). It can generate both application launchers and installers.
I'd hate to repeat myself too much, so check e.g. this earlier answer where I plugged it (as installer builder, but it doesn't make much difference here).
Summary / bottom line: install4j can create native .exe launchers that absolutely do not depend on a pre-installed JRE (or any other specific libs), and it offers flexible options for bundling (and detecting) JREs.
回答5:
Netbeans allows a Java SE project to be packaged in a native application installer, embedding a JRE. It's here :https://netbeans.org/kb/docs/java/native_pkg.html :)
回答6:
Another example... Bundle Java (the JRE) and Launch a Java App with 7zip SFX! ... (Convert Java Apps to an Executable, sort of)
回答7:
I know I'm a little late to this party, however it looks like ej-technologies (love their stuff) has a new solution called exe4j
which will do exactly as the OP wanted without any funny business needed.
http://www.ej-technologies.com/products/exe4j/overview.html
If you are working in an OpenSource project, they provide free licenses (you just need to contact them). If it's a commercial project, then a license is required... but at $69 USD for a license, it's darn cheap and worth while imho.
From their website:
If you want your own process name instead of java.exe in the task manager
and a user friendly task-bar grouping, exe4j does the job for you.
exe4j helps you with starting your Java applications in a safe way, displaying
native splash screens, detecting or distributing suitable JREs and JDKs,
startup error handling and much more.
回答8:
JSmooth can do this according to the documentation. I have only tried it without an embedded JRE, but been very satisfied. It is scriptable with ant and we build on Linux.
http://jsmooth.sourceforge.net/features.php
回答9:
You might take a look at: http://ulibgcj.sourceforge.net/uswt.html It has micro-swt library that make easy to build GUI using SWT and have a look at Eclipse GCJ Builder
回答10:
Install4j is a great tool for this kink of purpose.Also you could check out JSmooth or launch4j-all though I have tried to bundle jres with JSmooth and was not able to..
回答11:
I found Engima Projector x86 / x64 better than BoxedApp Packer
If you get soft miminizejre by packr than copy your application myapp.jar into launcher\jre\bin\
and copy from installed jre example C:\Program Files\Files\Java\1.8.0_xxx\bin\javaw.exe to launcher\jre\bin\
Open Engima Protector input -> javaw.exe from launcher\jre\bin\
And go Options if you want high compress and Find Miscellaneous -> Command line "-jar myapp.jar"
And click protect and wait for whole dlls and jar into exe
Make sure your myapp.jar should generate by Eclipse with "Package required libraries into generated JAR" because you don't worry if you have imported many libraries example lwjgl or JavaFX than you must check if embedded javaw_protected.exe has included important files example assets.
But BoxedApp Packer is same too BoxedApp Packer is bit bigger than Engima Protector. Protector is almost best small embedding javaw.exe with assets / resources. Than they can't crack jar files... I hope you are happy with own jar into exe as less 4 mb without lib directory - If you have problem with jvm.cfg error message It means you don't copy embedded exe into root directory of jre or jdk
Please make sure embedded exe is here outside of jre or jdk root directory.
I hope you haven't problem if you use Protector x86 than it need use i586, Protector x64 for jre x64
If you use Protector x64 with jre x86/i386 - It is okay no problem. It works fine.
Best regards
// EDIT:
UPDATED NEW VERSION EXCELSIOR JET + VIRTUAL BOX OR PROTECTOR are almost best "embedded applications"
Check youtube: https://www.youtube.com/watch?v=ctbIxq-1MGE
来源:https://stackoverflow.com/questions/2258932/embed-a-jre-in-a-windows-executable