How to create java jar files?
You would have seen or heard about the java jar file. Java jar file corresponds to the archived form of java classes (normally with the extension .jar).
jar = java archive
It is not mandatory that a jar file must contain only the class (*.class) files. It can contain directories, images, class files or other media content. For our further discussion on the topic, we will consider the example given here. We will first create an archive of the class files.
$ javac tutorials/sutils/StringUtils.java #compile StringUtils.java. StringUtils.class is available in tutorials/sutils $ javac tutorials/wmessage/WelcomeMessage.java #compile WelcomeMessage.java. WelcomeMessage.class is available in tutorials/wmessage/ $ jar cf tutorials.jar tutorials/sutils/*.class tutorials/wmessage/*.class
You can view the contents of the java jar file. You will see that tutorials.jar will only contain the above two classes.
So the option cf with the command jar creates an archive.
As said above, it is not necessary that jar must contain only class files. It can contain directrories, images, or any other media or (configuration) filesĀ used by the java classes.
$ mkdir tutorials/media $ jar cf tutorialswithmedia.jar tutorials/sutils/*.class tutorials/wmessage/*.class tutorials/media
Check the contents of tutorialwithmedia.jar
Comments: