How to package java files into jar files
The day before yesterday, I saw an article about how to package jar files. I felt pretty good. I tried it myself and added my own opinions and exercises.
Now, I put my summary here for your reference. These are all actually compiled and absolutely feasible. What do you not understand,
Welcome to the discussion, because there is no time for another method to operate files in batches, which is not listed.
1. How to package a Java file to the current directory?
Javac-D. *. Java
2. How to package and compile a Java file into a specified folder?
Javac-D object_file *. Java
3. How to Create a jar?
① Compile and generate the. Class file as above 1 and 2
Prepare a configuration file with a name such as conf.txt. Enter a line in the file:
Main-class: packagename. class_filename (Press ENTER)
Note: The start of the file must be written in the top space, and there must be no space. Main-class: there must be a space behind it. In addition, this line must start with
Press enter to finish. This configuration file shows which class to run when double-clicking the JAR file.
③ Run the following command to create a jar file:
Jar CMF conf.txt jar_name.jar packagename/*. Class
The parameters of the conf.txt and jar_name.jar files are m and F respectively. The role of conf.txt is to configure
Manifest. MF file. It is not enough to specify a manifest. MF file to create an executable JAR file package, because mainfest
Yes. Both jar files and unexecutable jar files contain manifest. The key lies in the manifest of the executable JAR file package, and its content package
Including main-class items