Creating libraries

We will create a library folder upon project creation. For this recipe, we will create a Java EE project.

A library consists of a set of files that are packaged inside a compressed file. Many files can exist inside a library but usually, in Java, libraries contain only class, JARs, and configuration files. Libraries in Java can have different extensions.

Libraries in Java can have different extensions:

  • JAR: An acronym for Java Archive. This file extension is built on top of a normal ZIP file to aggregate various files.
  • WAR: Web Application Archive means that this file is responsible for obtaining Web Application related files. Example: images, Java files, JSPs, Servlets, XMLs, other JARs, and so on.
  • EAR: The Enterprise Archive usually encompasses all the other files combined. Normally it contains other WARs (and will also hold the same file types), configuration types, and other JARs. This file is better suited to compact into a single file, many different modules of an application.

Both WAR and EAR are built on top of JAR. These files will be explored in future recipes so for now we will only work with normal JAR files.

Getting ready

Please refer to the Getting ready section of the previous recipe for necessary tools and configurations.

Once that is complete, it is possible to continue to the next section.

How to do it...

  1. Create a New Project by either clicking File and then New Project, or pressing Ctrl+Shift+N (shortcut).
  2. In the New Project window, choose Java Web on the Categories side and Web Application on the Projects, then click Next.
  3. At Name and Location, click on Use Dedicated Folder for Storing Libraries.
  4. Now, either type the folder path or select one by clicking on Browse.
  5. After choosing the folder enter Project Name as CreatingLibraries and, proceed by clicking Next and then Finish.
How to do it...

How it works...

Since we are creating libraries, a new project is going to be needed for this purpose. Projects can be packaged as libraries and reused in other projects to extend their functionality. Let's not worry about changing any of the default values that are set by the IDE for Project Name and web servers, since it is not a part of the scope of this recipe.

When selecting Use Dedicated Folder for Storing Libraries, it should be noted that this is where the libraries required for compilation will be stored.

NetBeans will perform the heavy lifting of copying all the necessary libraries to the specified folder. After following these steps, a new project will be created with the shared libraries folder at the chosen location.

There's more...

The usage of a Java Web project is just to exemplify; but projects in normal Java, Java ME, or Java EE would also follow these same steps with the same results.

If you are feeling curious, a good suggestion is to check the folder and file structure of the newly created lib folder.

There's more...
..................Content has been hidden....................

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