A JAR (Java Archive) is a file that contains a collection of classes. As an example, let's say sample.jar file has the following. This means that sample.jar has two classes. One class is com/main/people (or com.main.people) and the other class is com/main/places (or com.main.places).
Apps can be configured to use one or more of the classes in the JAR. For an app to be able to use a class in the JAR, the app needs to be able to access the JAR. There are 3 ways an app can access the JAR.
- App - When compiling the app, you can include the JAR in the app. This is OK if no other apps need to use a class in the JAR.
- JVMs classpath - You can configure the JVM to use the JAR. This makes sense when two or more apps in the JVM need to use a class in the JAR.
- Shared Library - You can create a shared library that contain the JAR, and then configure JVMs to use the shared library. This makes sense when apps in different JVMs need to use a class in the JAR.