How To Create Exe File For Java Web Application
If you are a Java programmer then you know what is the purpose of the JAR file, but for those who are unaware, the JAR file is deliverables of Java application. Just like C and C++ applications produce EXE files, Java produces JAR files. In other words, A JAR (Java Archive) file is a ZIP format file that bundles Java classes into a single unit, it may contain all the resources needed by Java application as well. There are mainly two types of the JAR file in Java: Library JAR (normal JAR) files: JARs which are reusable libraries like Apache commons JAR file, guava.jar itself, or even JDBC drivers likeojdbc6_g.jar. There is another type as well, Executable JAR files: JARs which can be executed as standalone Java applications.
The main difference between normal and executable JAR file is that later contains a manifest file, which specifies a main-class entry. When you run that JAR file, Java starts your application by reading that main-class entry, because you need the main method to execute Java programs.
I had earlier shared steps to create a JAR file from the command prompt, which if you have not read, go read it. You will learn about the basics of the JAR command, which comes with JDK, manifest file, and different attributes of the manifest file.
In this tutorial, we will learn how to make/create/export both library and executable JAR files in Eclipse IDE. Why it's important to know creating executable JAR in Eclipse because it's one of the most used tools by Java programmers.
Once you know the steps, you export your Java program as a JAR file in a second or two. After creating an executable JAR file, you can follow these steps to run the Java program from the JAR file in the command line.
Steps to Create Executable JAR file in Eclipse
A picture is worth more than a thousand words, that's why I have provided all steps by taking screenshots. You can quickly learn how to create executable JAR for your Java application in Eclipse, by just looking at these screenshots. They are arranged from start to end. This means the first image is for the first step and the last image is for the last step.
By the way, if your application is dependent upon some other JAR files e.g. third-party library, then don't need to include them inside JAR. All you need to do is include them inside your Java Classpath. Java is smart enough to pick classes from those JAR.
Also remember to include the main method or entry point of your Java program, while creating executable JAR, as you can not run a Java program without the main method, as discussed here.
Step 1
Select your project and click on the Export option.
Step 2
Choose Java and select JAR file for exporting
Step 3
Now select the source and resources you want to export into a JAR file. After selecting the src folder and any resource, select the destination folder, where you want your JAR file to be created. Also, don't forget to check the option "compress the content of JAR file". This will reduce the size of the executable JAR file. If you want you can finish the process in this step, but you can also go one step further to save these instructions of executable JAR file creation for future use.
Step 4
In this step, you can save all instructions into a "JAR description" file for future use. This will create a description file e.g. Test.jardesc in the chosen folder.
Step 5
This is an important step because you are going to generate the manifest file, don't forget to choose the main class. This is important to make your JAR an executable JAR file. Remember the main method is the entry point of any Java application.
Step 6
You are done with creating an executable JAR file. Now you can go to the target folder, which you have chosen in previous steps to see both the JAR file as well .jardesc file to recreate the JAR file again and again. This time you don't need to include main class as well, as those are already included.
Step 7
After making code changes, if you want to create a new JAR file, you don't need to go through all previous steps. This time, just select your JAR description file and say "create JAR", a right click menu option in Eclipse. This will create another JAR file in same folder. You can double check timestamp of JAR file.
That's all about How to create or make an Executable JAR file in Eclipse IDE. By following these steps you can export your Java program as executable JAR, which allows you to share your program with your user, client, and anyone who wants to take a look. I strongly suggest saving instructions to export the JAR file, so that you don't need to run through all these steps again and again. Next time, when you update your code, just click on your jardesc file and your JAR file will be ready in a blink.
How To Create Exe File For Java Web Application
Source: https://www.java67.com/2014/04/how-to-make-executable-jar-file-in-Java-Eclipse.html
Posted by: drakeimensid.blogspot.com
0 Response to "How To Create Exe File For Java Web Application"
Post a Comment