Engineering Full Stack Apps with Java and JavaScript
Java provides JAR files to bundle your application easily distribute. The jar command below create a JAR file called MyJar.jar and it will contain the myApp directory and myApp's entire subdirectory tree and files.
jar -cf MyJar.jar myApp
There are more options for jar which can be used for viewing the contents, unzipping etc. JAR stands for Java Archive and you can open it or extract it using any archiving tools like winzip or winrar. We will see jar files in detail later.
Finding a JAR file using a classpath is similar to finding a package file in a classpath. The difference is that when you specify a path for a JAR file, you must include the name of the JAR file at the end of the class path, not just the directory in which the JAR file is located.
Consider an example:
Class Book needs to access class Paper. The Paper class is deployed in a JAR named myLib.jar. Assuming that the JAR file is located at /foo/myLib.jar, the Book class is compiled as:
javac –classpath /foo/myLib.jar Book.java
Or if a classpath environment variable is set that includes /foo/myLib.jar, then you can simple compile as 'javac Book.java'