0

Can any one please suggest me that how can I create .exe wrapper to install my Java application.

Currently Iam using the following command to install my application.

"java -jar application.jar"

After googling I came to know that we can create .exe by using some third party tool which is open source.

But don't know exactly which is best for my requirement. I have only application.jar with me as an input.

Thanks In Advance.

JSP
  • 447
  • 2
  • 8
  • 21

2 Answers2

2

In order to make the command double-clickable, you have two options.

The first is a bat file with exactly that string "java -jar application.jar" in it, which is double-clickable just like exe.

The second is to make an exe by compiling the following C program.

int main(){
    system("java -jar application.jar");
}
merlin2011
  • 71,677
  • 44
  • 195
  • 329
  • 1
    please note that it requires Java Runtime Environment to be installed. It is better to use an existing java to exe wrapper like launch4j to bundle jar file with JRE, otherwise some users will be unable to start this exe file. –  Jun 24 '14 at 05:26
  • @RafaelOsipov, Fair point, but if the user was originally installing using `java -jar`, my assumption is that the target user already has the `JRE` installed. If that assumption is incorrect, I hope the OP will comment here and correct it. – merlin2011 Jun 24 '14 at 05:27
  • merlin, can you please suggest me how can I bundle the jar into the exe. – JSP Jun 24 '14 at 05:31
  • @Honey, You can either use an existing package like Rafael suggested, or you can switch to the `C#` equivalent of this function and use the methods suggested in [this question](http://stackoverflow.com/q/6349004/391161) to turn the `jar` into an embedded resource. – merlin2011 Jun 24 '14 at 05:33
  • merlin...in future if I give to my friend where there is no JRE, then we need to bundle the JRE as part of exe. – JSP Jun 24 '14 at 05:34
  • @Honey, Then you should try `launch4j` as Raphael suggested. I am not advertising it because I have never used it and have no idea how easy or hard it is to use. :) – merlin2011 Jun 24 '14 at 05:35
  • Thanks Merlin and Rafael for your valuable reply and will try to use Launch4j. – JSP Jun 24 '14 at 05:40
1

I like to use 7zsd.sfx to create installers for my java applications.

Directions:
1.) install 7zsd.sfx from http://7zsfx.info/en/ and install 7z
2.) create a .7z archive
3.) add all the jre files required to run the java application to the archive
4.) add the application itself to the archive
5.) add a .bat or .exe file (for windows) to install the files after 7zsd.sfx extracts all the files
6.) add a .bat or .exe file to run the java application using the jre files
7.) create a file (preferably named "app.tag") with a structure such as that below (add your own parameters)

;!@Install@!UTF-8!
Title="My App"
BeginPrompt="Do you want to install My App?"
Progress="yes"
ExtractDialogText="Please wait while app files are being extracted..."
GUIFlags="32"
ExtractTitle="Installation"
FinishMessage="My app has been installed and added to your desktop."
RunProgram="setup.bat"
;!@InstallEnd@!

The RunProgram is the program that runs after the files are extracted to a temporary folder. This program should create a permanent folder to hold the necessary extracted files (jre, java application, and executable to run app with jre). Additionally, the program should create a nice, good-looking shortcut for the executable file used to run the app and it should move it to the desktop and add an icon.

Finally, to create the exe which will install your files, go to the command line and access the folder with 7zsd.sfx and type in the following command:

copy /b 7zSD.sfx + [pathToDirectory]\app.tag + [pathToDirectory]\yourAppArchive.7z [pathToDirectory]myExeInstaller.exe