Introduction to Java Packaging

In the Java universe, there are three basic types of files:

  • Class files
  • Other applications' resources, such as scripts and images
  • Meta-information files

Class files contain Java source code translated into bytecode. Bytecode is then executed by JVM. Such files are easily recognized by their .class suffix. The Java code is solely contained in those classes. However, a Java application may require additional resources during the application's runtime: websites may require images to be served to the client, or a simulation may require a file with an initial simulation state. Simply put, any non-Java-related file is considered to belong to the group of other application resources, with one exception: files that contain meta-information about the application itself. Security-related information, information about an application's version, or application configuration data are considered meta-information. Developers mostly influence class files and application resources, as these directly reflect the application being written. The application is a general term we are using, Microservices can also be considered as Java applications when it comes to packaging.

An application is a set of directories that contain classes and related resources. For an application's users, it is easier to obtain one archive with the whole deployable. There are more types of archives in the world of Java:

  • Java Archive (JAR)
  • Java Web Archive (WAR)
  • Java Enterprise Archive (EAR)

A  JAR is a basic form of packaging used in the Java universe. Other forms of packaging build on top of the JAR, extending functionality. A JAR contains all application classes and some meta-information, such as the application version. Also, the whole JAR, as well as any other archive, can be digitally signed using the Public key infrastructure (PKI). A JAR file can be considered as a ZIP file with a standardized inner layout. Compression is completely optional.

A WAR uses the same principle as a JAR. It was first introduced with the Servlets standard. The main benefit of introducing WAR files is new types of web-related content, such as servlets or web pages. A web archive may also contain multiple JARs. Commonly, these are libraries or different parts of the application.

The most complex and rarely used type of packaging is an EAR. An EAR file provides a means to bundle multiple WARs and JARs into a single package. An EAR provides means to define the deployment order of the archives contained in it. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.156.251