How to create .exe wrapper to install the Java application - java

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.

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");
}

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

Related

How to add jdk in a.jar file and run it

I have made a runnable .jar file. I want to run it on a PC which does not have jdk instilled, Can I add jdk in .jar file itself and run it ?
Suppose that your have installed your Java in the following path:
1 - copy this jre folder
C:\Program Files\Java\jdk1.7.0_25\jre
now all you need is to create a .bat text file with the following content:
#echo off
jre\bin\java -jar your_filename.jar
2 - name it as run.bat
that's all you need.
To wrap up things, the directory structure should be:
|---jre
|---bin
|---... // other files and folders
|---run.bat
|---your_filename.jar
click or create shortcut from run.bat and that's it.
If you are more interested in having a stand-alone executable file, then take a look at Launch4j (google it :) )
You don't need the JDK for it to run, just the JRE (Java Runtime Environment). You can download the JRE from here.
This is, unfortunately for you, something that will be needed to execute your code.

How do I make a final executable file for my Java program?

I created a tic-tac-toe game in Java. It runs fine on Eclipse.
How do I compile this file (which is currently a .java file) to the standard file format of Java applications, so it can be run from the desktop like a normal program?
What is the standard file type for the final executable Java application? What should be the file type if I want people to easily and without any computer knowledge run my program on their computers?
with eclipse right click on your project. then export it as a runnable .jar file.
Project Right Click > Export > Runnable .jar File.
First choose your project under "Launch configuration", then choose your destination.
After that click finish. Your program should be in your destination folder. Double click to start (just like an .exe file)
For example: If you export it to your desktop, and you name it "TicTacToe", the file on your desktop is "TicTacToe.jar" - ".jar" is your executable file
Done
You have to compile your java class first
javac TicTac.java
and then execute it
java TicTac
Note: that here you provide the name of the class with the main method!
As the other answers indicated, you can create an executable jar using eclipse (or a number of other tools). What these tools are doing under the hood is defining the Main-Class: attribute in the jar's manifest.
In Windows, your users can double click on an executable .jar to launch it, as long as the file associations are configured correctly. However this may not be obvious to windows users who are trained to expect some sort of .exe extension.
To solve this, you could use launch4j to wrap your executable jar in a windows executable. Note: this doesn't change your java application into a native application (it still requires the JVM, etc), it simply makes it launch more like a native application.
For deploying Java desktop apps., the best option is usually to install the app. using Java Web Start. JWS works on Windows, OS X & *nix.
Note that JWS is more effort for us to deploy (it involves not only Jarring and signing the code, but creating a JNLP launch file and a page on the net or network to check that Java is installed & serve the files to the user), but is super easy for the end user.
If there is a JWS deployment, the Jar does not have to be an 'executable Jar' as described in the other answers.
The command should be javac yourFile.java from you command prompt and then after compilation, class file is created. You can run it using java MailClassName
You can find a good tutorial on using javac and java commands here.

Wrap the application to create sh file in Ubuntu Linux

I have created one java application which takes number of external jar files and also VM arguments passed to it.
I want to create .sh file for that application so that I cat run it on any linux system.
Please suggest me any tool to create .sh file in linux and which will also takes care about the arguments which has to be pass to application to run it.
I have use the tool named JarSplice but its not working as there is problem in loading libraries after creation of sh file .
So please suggest any tool for that.
If you're using maven to build your application there is a plugin called appassembler-maven-plugin that can create a .sh file for your application.
The groupId is org.codehaus.mojo.
You need to generate an executable jar, then you can simply run "java -jar main.jar" from there.
There are many questions on stackoverflow on how to create executable jars (you need ot set stuff in the MANIFEST.MF file in the jar file), for instance:
How do I create executable Java program?

How to create an executable (a file that starts the program on double-click like an .exe) in JAVA with Eclipse?

I've created a program in java and now I want to create an executable from it.
I'm new to java, I don't know if it should be a .exe.
I'we exported my project to a .jar file, but when I double-click it it opens "open with" window.
I want to export my project to a file that runs my program on double-click.
Is there any solution?
Export --> Java --> Runnable Jar file --> Specify the class with static main method to run.
Double click on the Jar file to run..
Thanks...
Java compiliation creates byte code for the JVM, so a native, binary executable is not created during compiliation (like C or C++ programs). This is a feature of Java.
To deploy an application to multiple systems they must have the JRE. These .jar files can be launched from the command line (see this: http://download.oracle.com/javase/tutorial/deployment/jar/run.html)
Some vendors get around this with batch files that launch the JRE to run their application's JAR (and then put these in the start menu, desktop, etc with a fancy icon).
If you want people to install your app (especially from a web page or over a network) you probably want a Java Web Start package (see this for crating one in Eclipse: http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fjava_web_start.htm)
If you just want it to be runnable on your computer, you can use the open with dialog to open it with javaw.exe in JDK_DIRECTORY\bin. Alternatively, if you really wanted to make it an EXE, you could look at some of the answers here.
Either do as in the link mentioned by #dacwe or I would suggest to depending on operating system set a permanent connection between java and jars, then it will always happen.
On Windows you do it by right clicking on any jar then open with and find your javaw.exe in bin folder of your jre installation.
I think you are looking for a simpler approach than Java Web Start.
I assume that you are a Windows User, since you want a .exe file.
So once you have the exported MyProgram.jar file, you only need to create a .bat file
that contains a sole line:
java -jar MyProgram.jar
and place this execute.bat file in the same folder as your MyProgram.jar
This approach works for Linux too, only you need to place it inside a similar file and execute the same command.
Read here http://javabeanz.wordpress.com/2009/01/29/running-an-executable-jar-from-command-line/ for more explanations.

How do I run a .jar executable java file from outside NetBeans IDE?

How do I run a .jar executable java file from outside NetBeans IDE? (Windows Vista). My project has a .jar file created by Netbeans. We'd like to run it. Either: how do we run the file or how do we create a 'proper' executable file in NetBeans 6.1?
Running a jar is as simple as
java -jar filename.jar
as Laplie said, java -jar your.jar
EXECUTABLE file : see this thread for answers How can I convert my Java program to an .exe file?
One of the best technique to run the jar file or jar jar file
Create the jar file by jar command choose your jar filename
Java_Jar_File.jar
Run the jar file us the command like java -jar Java_Jar_File.jar
You can do it from the command prompt if java isn't in your path by finding the full path to your java install, something like:
C:\java\java.exe -jar C:\jar_you_want_to_run.jar
or if java is in your path:
java.exe -jar jar_you_want_to_run.jar
This will run the jar produced by netbeans.
First, make sure you set the Main Class in your NetBeans project properties dialog.
Then, you can either
Double-click the jar file (This should work on any machine with an installed JRE)
or
Make sure that java.exe is in the path (or replace java below with the fullpath and file name of the executable), put the following in a batch file:
java -jar filename.jar
Then you can double-click the batch file instead of the jar (useful if you have people unaccustomed to using naked jar files)
OR
You can go down the path described here How can I convert my Java program to an .exe file? to build a .exe for windows.
Make a BAT file with
java -jar filepath.jar
from a command prompt you can run this command: java -jar your_jar.jar.
To run a java jar file its file association should be properly configured. There is a free tool called jarfix to fix all jar file association problems. Run this file to fix all jar issues.
In the project properties dialog in NetBeans you need to set the Main Class - otherwise the generated .jar will not be executable. Then, as already indicated, either double clicking on the .jar or the command java -jar will start the program.
If you have problems with running your jar, make sure you are trying to run your current version to get newest version in Netbeans: GoTo Run Menu --> Clean and build

Categories

Resources