iSeries EGL

All things EGL for the iSeries / i5 / Power System

Archive for the ‘Creating a Jar File’ Category

Exporting Java Classes Into a .jar-file For Use In Other Projects

leave a comment »

Introduction

This post describes how to export Java classes to create a .jar-file so that the exported classes can be reused by other projects. This is presented in an EGL project context, but the same steps are involved for any Java project as well.

Export the Java Class

The screen show shown below starts the process by ight-clicking on the Java class to expose the popup menu from which the Export option is selected.

Fig.1 – Begin by right-clicking the class to show the pop-up menu.

To continue with the export process follow the options as shown by the following screen shots.

Fig.2 – Select the option shown and select “Next”

 

In this screen shot, open and select the package (or packages) containing the Java class (or classes) to be exported. Select the package required and the destination directory.

Fig.3 – “Finish”

 
 

Importing the Jar File into Your Project

Copy the .jar-file to the project’s lib directory as shown. This is where all of the project’s .jar-files reside.

Fig.4 –

 

Select the project directory as shown and right-click to expose the pop-up menu. Add the .jar-file to the project’s build path as shown

Fig.5 –

 

Select the tab marked “Libraries” and then select the button marked “Add JARS…”

Fig.6 –

 

Expand the project directory then the directory labeled “WebContent” and finally “Lib” as shown. Select the .jar-file to be added. In this case, there is only one.

Fig.7 –

 

When completed you will see the .jar-file under the lib directory as before however, because it is now part of the project’s build path, it has been included among the other .jar-files under the project.

Fig.8 –

 

Summary

This post illustrated how to export a Java class into a .jar-file and then import it into an EGL project for reuse. Placing the .jar-file in the “WebContent/lib” directory gives the project access to those resources when the project is deployed onto Tomcat however, the IDE is not aware of them. By adding the .jar-file to the project’s class path or build path it gives the IDE access to the classes during development (content assist) and when it builds the project for running inside the IDE.