1. In eclipse, right-click on the project name to be typed into a jar package, and the following pop-up box appears, select "export":
2. Click "jar file" in the next interface, and then next:
3. In the next interface, check the project to be packaged and other options, such as test project, as shown in the figure; then click the browser pointed to by the arrow on the right, select the directory to save the jar package, and at the same time name your jar package. For example, I choose to store it on the desktop, with the name jarTest; then click "next", and click "next" again in the pop-up interface:
4. After "next" twice in the previous step, the following interface will appear. Check the options shown in the figure above, and then click the browser pointed to by the arrow to select the entry of the program, that is, the main method of java (if it is not an executable jar package, you do not need this step of choice):
5. After the previous step, a selection box will pop up, including all the mian methods in this project. If there is no main method in the program, nothing will be displayed in the popup box. For example, there are three main methods here. I select jarTest and click "ok":
6. After Ok, the jarTest you just selected will appear in the text box behind mainclass. Click "finish":
7. After finishing, the following pop-up box will appear, prompting that the jar package is exported successfully:
8. Then we can see a jarTest.jar file on the desktop. If we have installed jdk on our computer and equipped with environment variables, then double-click the file directly, and the program will start executing from the selected mian method:
9. For example, the code in main of my jarTest is as follows. When running this program, a file ending with .log is generated on the desktop, and then loop into the five elements:
10. My computer has installed jdk and environment variables, so you can double-click the jarTest.jar file to execute the program, and then you can see a new file at the end of .log on the desktop. Open this file and you can see that the five elements are written inside, proving that this executable jar package has been successful:
The above is all about this article, I hope it will be helpful to everyone's learning.