After completing a project in Eclipse (in a Windows environment), you will need to turn it into an executable. The easiest and fastest way to launch a Java project is to create an executable file (.exe). This tutorial will show you how to convert a regular.jar file into an executable.
Steps
Part 1 of 3: Export from Eclipse
Step 1. Right-click on the project, then click "Update" (or F5, if you use keyboard shortcuts)
This step is used to update the project, in order to avoid conflicts during the export phase.
Step 2. Right click on the project again and select "Export" from the menu that appeared
Step 3. Expand the "Java" folder and click on the "Executable JAR File" item
Step 4. Configure the JAR file settings
The first thing to do is to select the main class (the class with the Main method), using the drop-down menu under "Launch configuration".
- Next, select the destination path, using the "Choose …" button or typing the file path.
- Finally, verify that you have selected the "Extract the required libraries in the generated JAR file" item. Disregard the other menu items and click "Finish" when you think you have completed.
Part 2 of 3: Create the Program Icon
Step 1. Search or create the image that you will use as the program icon
Keep in mind that the icon is an important part of the program's graphics. It is used every time the executable is started and is probably always present on the desktop! So try to choose it carefully, so that it is indicative of its content. The size of the icon needs to be 256x256 pixels to work properly.
Step 2. Open your browser and go to the convert site
com.
This free site converts your images (.png,.jpg) into icon files (.ico).
Step 3. You can select the image by indicating its URL or by indicating the file path
Click on "Go" to confirm and start the conversion.
Part 3 of 3: Creating the Executable File
Step 1. Download launch4j
This program is free and is designed for putting resources into an executable file. To download it you can go to this address.
Step 2. In the first text field, type or select the folder where you want to place the executable file
Obviously, the file must have an ".exe" extension.
Step 3. In the second text field, instead, type or select the.jar file you exported from Eclipse
Step 4. In the fourth text field, the icon field, type or select the.ico file you converted
If you choose not to indicate the icon, your operating system will use the default one for executables.
Step 5. In the JRE tab of the top panel, under "Min JRE version", type in “1.5.0”
This way, users will most likely have a version of Java that is compatible with your program and will have no problem using it. You can choose the release you want but 1.5.0 is definitely an optimal version.
Step 6. Click on the settings button, marked with a cogwheel, located at the top
Step 7. Name the.xml file with an appropriate name and save
The xml file is a standard type, so you won't have any problems. Finally, your executable file will be created!
Advice
- The image size must be 256x256 and remember to select the.ico file in launch4j.
- Check that all file extensions are correct (.exe,.jar,.ico,.xml).