23

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.
Freeman
  • 9,464
  • 7
  • 35
  • 58
  • If you convert the jar to an exe (on windows I suppose?) it will probably pull half the jre in the exe to satisfy dependencies. – extraneon Feb 16 '10 at 10:30
  • http://yuvadeveloper.blogspot.com/2009/03/convert-jar-files-to-exe.html –  Aug 22 '10 at 18:11

9 Answers9

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

Einar
  • 1,001
  • 3
  • 11
  • 28
extraneon
  • 23,575
  • 2
  • 47
  • 51
  • The link does not work, presenting the actual solution is a better way to answer the question (tell the program you should use, or the procedure you must follow) – Roalt Jul 22 '19 at 07:09
  • The link pointed at Java to Exe should be modified to https://web.archive.org/web/20181117071040/http://www.excelsior-usa.com/articles/java-to-exe.html. – Anjana Oct 20 '22 at 05:19
9

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/

Ganesh Shankar
  • 4,826
  • 8
  • 43
  • 56
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.

Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139
  • I can't really see platform independence as a requirement. You generally target an audience, not a platform. If they have standardized on an environment you could target AND test that. – extraneon Feb 16 '10 at 10:43
  • I meant that such a tool would not be shipped with JDK due to platform independance reasons. JDK ships tools to build and package apps for any platform on any platform. – Thorsten Dittmar Feb 16 '10 at 12:20
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.

icktoofay
  • 126,289
  • 21
  • 250
  • 231
3

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

ponkin
  • 2,363
  • 18
  • 25
3

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.

brian_d
  • 11,190
  • 5
  • 47
  • 72
2

Launch4j worked for me while some tools hadn't been working. It also have a good guide here.

Hope this help!

Huy Hóm Hỉnh
  • 597
  • 7
  • 18
0

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)

Pramod
  • 391
  • 5
  • 21
0

1) To create the exe, you can use Launch4j

2) As I have seen, you cannot encrypt the jar contents. I'm not sure though.

3) To create the installer you can use the exe you just created and use InnoSetup to create the files. You have to embed the jre inside the installer and also any other libraries and extra files that may need in the runtime. When embedding the jre, the setup gets large and if you want to avoid that, you can ask the clients to install java in the machines. That way, you wont need to ship with the jre.

dilanSachi
  • 562
  • 6
  • 14