How can I convert a JAR file to an EXE file?

I want to created a JAR file and I want to run it on a client machine.So, I have a couple of questions:

  1. How can I convert the JAR file to an EXE file?
  2. 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.
  3. 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.

Solution 1:

  1. See this link: Java to Exe. It also explains what valid reasons are to do this, and when you should not.

  2. 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.

  3. If you have an exe there are installers enough.

Solution 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/

Solution 3:

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.

Solution 4:

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.

Solution 5:

May be Excelsior JET will satisfy your needs.) IMHO very mature product.