This is only a single post about how to create a JAR file using command line easily. Previously, you need to compile your Java files, if you want to read more about it, please see this post: How to compile Java programs by using command line.
If we need to create a JAR file, we can run next command (if we are in the root of our project):
// Create a JAR file including com and WebContent directories and their contents
jar -cvf web_fragment.jar com/ WebContent/
- c: indicates that you want to create a JAR file
- v: produces verbose output on stdout while the JAR file is being built. The verbose output tells you the name of each file as it’s added to the JAR file
- f: indicates that you want the output to go to a file rather than to stdout
- Last list of parameters are folders we want to add. We include com/ and WebContent/ directories and their contents into the JAR file.