问题
I want to created a JAR file and I want to run it on a client machine.So, I have a couple of questions:
- How can I convert the JAR file to an EXE file?
- How can I encrypt the JAR file's contents? The jar file could be extracted with WinRAR and the classes could be decompiled with any Java decompiler.
- How can I create an installer? My clients doesn't have any JVM and I don't want to ship JDK or JRE along, because they have big size.
回答1:
See this link: Java to Exe. It also explains what valid reasons are to do this, and when you should not.
You can't really encrypt binaries as the machine has to understand them. That said, an optimized executable is very difficult to decompile, while plain class files are ease.
If you have an exe there are installers enough.
回答2:
JSmooth is a application which will wrap your Jar in an exe
it also allows you to check if the correct version of JRE is available on the system you're deploying to
http://jsmooth.sourceforge.net/
回答3:
You can't prevent decompilation. The best you can do is make it harder or more time-consuming to do so. As an answer to your question though, I believe you can use gcj to compile Java into EXEs.
回答4:
As for 1): I guess you can not. There may be tools out there, but you cannot do that with standard tools shipped with JDK, as it would destroy platform independance. (See other answers providing links to such 3rd party tools)
As for 3): Use InnoSetup to create the installer. Include JRE within setup and let InnoSetup install it on the fly.
回答5:
May be Excelsior JET will satisfy your needs.) IMHO very mature product.
回答6:
1) I have recently tried the program jarToExe and like it. Some features are:
- free basic version or very cheap ($30) for 'enterprise'
- ability to have windows task manager list your app's name instead of the default java.exe
- extra obfuscation
- runtime check that java is installed
2) You can make it harder to reverse engineer using proguard or other obfuscator
3) nsis is a very powerful, free scripting language to create windows installers. Good documentation on the site wiki and support on stack overflow as well.
回答7:
Launch4j worked for me while some tools hadn't been working. It also have a good guide here.
Hope this help!
回答8:
We use a 7zip SFX install launcher. This is an open source simple tool. It will package your jar, a version of jre so it's not mandatory for the installing systems to have jre installed and a self extracting version of 7zip. Here is a tutorial which explains how to bundle and GitHub link The project is not maintained but works perfectly(tested until Java 1.8)
来源:https://stackoverflow.com/questions/2272107/how-can-i-convert-a-jar-file-to-an-exe-file