I want to create .exe file for my java project and give it to my friend. I wrote my project in eclipse and it uses sqlite. I don't know how to make a .exe file that can be run in other PCs. Can any one help? P.S:I saw this link but it is not useful for me! Create .jar of an eclipse project that uses Sqlite DB
-
1Deploy the app. using [JWS](http://stackoverflow.com/tags/java-web-start/info) & give your friend a link instead. This will also work for your friends on OS X & *nix. – Andrew Thompson Jan 08 '12 at 03:11
-
How should I deploy app? I am not familiar with JWS – Sara Jan 08 '12 at 04:31
-
The term 'JWS' in my 1st comment was a link. The content at the end of the link was written by me & contains the best overview of JWS that I can muster, certainly in a comment. ;) It **will** be a learning curve to get a JWS deployment happening, but it results in a great experience for the end-user. – Andrew Thompson Jan 08 '12 at 04:48
4 Answers
.exe is a creature of Windows.
To run a Java program, you typically:
Create a .jar file (the "native" Java library format)
Write a DOS/Windows .bat file (or, equivalently, Linux shell script) to run your Java program (using the Java .jar file)
Optionally, create some easy-to-use mechanism for the end user to download the Java JRE (if it's not already installed on their PC).
Your .bat file can be as simple as this:
start javaw -jar myjarfile.jar

- 114,292
- 17
- 138
- 190
-
-
When I create .jar using eclipse and type "start javaw -jar myjarfile.jar" I have an error saying can not find main class! – Sara Jan 08 '12 at 01:48
-
1*"how should I create .jar file?"*. Use the JDK installation's "jar" command or whatever is provided by your IDE or build tool. *"... and how to write .bat file?"* Use a NotePad ... or any other text editor. – Stephen C Jan 08 '12 at 01:49
-
I went to eclipse>file>export>java>jar... but I have an error saying can't find the mail class – Sara Jan 08 '12 at 01:50
-
-
- First create an executable jar file by clicking on File menu, then export, and then select runnable jar file.
- Then select main class and click ok - the jar file will be created.
- After that use Launch4j application to create .exe. Launch4j is the best option for creating an exe file.
- Then use Inno Setup Creater to create an installer and it is done.
Have you considered creating Runnable jar from eclipse.
In eclipse, go to File > Export > Java > Runnable Jar.
There you ll find some options and you can use what suits you. The jar created should be able to run all by itself (obviously it needs the java run time).
Try this out.

- 9,550
- 2
- 33
- 29
I would recommend using a bat file. You can make a double clickable jar file, but I feel that is sometimes restrictive and not intuitive.
- Not many end-users know that a jar file is double clickable.
- You need to make sure the jar file has a main class and classpath defined. The classpath section in the jar file sometimes causes issues. Like you cannot reference a file or path on the file system. Only files or folders that can be relatively referenced from the location of the jar file.
- For windows users, you cannot easily make an exe file from a jar file. There are methods like using jsmooth, that will wrap your jar file into an exe file (bloating the exe file in the process).
The easiest way is to create a bat file. You can easily convert a bat file into an exe and make the exe file have an icon and everything. Link to a converter here:
http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html

- 8,181
- 7
- 39
- 65
-
-
1A bat file is just a file with an extension of .bat. The contents of the bat file will the be same thing that you use to run your java program from the command line. Like: java -classpath
.. Just put this line into a file.. name the file launch.bat