1. Manually package the directly executable jar package
1) First use javac to compile the java file and get the class file;
2) Create a new file with any name, for example, it can be called manifest, and the content is as follows (Note: 1. Add a space after the colon, 2. Finally, you must press Enter to a new blank line, otherwise an error will occur, as shown below. Enter another carriage return after addJarPkg);
Manifest-Version: 1.0<br>Main-Class: addJarPkg
3) Put the compiled class file and Step 2. Put the newly created file into the specified folder, such as test;
java video tutorial recommendation: java online tutorial
4) Run the command in cmd
jar -cvfm main.jar manifest -C test .
Pay attention to the path problem, where:
The "." after test represents all files, and the -m option after jar will merge the files created in step 2 into the in the jar package META-INF/MANIFEST.MF
, which is the update manifest configuration file, -C specifies the directory to be packaged, and the . after the directory represents all files in the directory.
2. Use the intellij idea tool to package a directly executable jar package
1) Click on the project
2) Click on the "" in the upper left corner of intellij idea File" menu -> Project Structure
The above is the detailed content of How to package into jar package in java. For more information, please follow other related articles on the PHP Chinese website!