Pramati Technologies

Compiling & Building Applications

The Build tool provided in Studio is used to compile individual files and build multiple files. The EJB Modules and Web Modules in the Desk are always in a "ready-to-deploy" state. The J2EE applications developed can be deployed properly once they have been compiled. This chapter helps understand how to build applications.

Methods of compiling files

The Build Tool is used to compile all Java source code, all JSP files, Servlets and archive files in Studio. Studio provides three ways to compile files in Studio:

Compile is used to compile individual files. Both Build and Clean Build options are provided on the modules in the Desk tree.

Build Settings

To configure the properties that the Build tool uses to compile and execute the specified files, use Build Settings. The settings can be specified separately for the Desk, EJB Modules, Web Modules and Java Modules. Changing the Build Settings of the specific folders can overwrite the settings specified at the Desk level.

Configure the Build Properties for the Desk Root

Desk Root on the Explore Panel > Right Click > Properties > Build Tab

Clicking on this brings up the dialog box with the Build Settings tab where the following build properties can be set:

Source Root Displays the source root of the Desk Root. This field is not editable.

Output Dir The target classes that have been built can be set for Desk. The default Output directory is <install_dir>/Desk_Root/classes. To change the output directory, click the browse button and select the new output directory. This field is editable for Java Modules.

Main Class Enter the project (Desk) main class in this field. To run this, use the keyboard shortcut, Ctrl + R.

Compilation option The compilation options can be changed according the requirement. The compilation options available in the Build Settings are

Classpath This field displays all class paths. The Class paths can be added and deleted from the field using the + and - buttons. The classpath entries of the Desk are displayed with grey background and black text. Entries in the classpath that do not exist in the file system are shown with white background and red text.

The order of the Classpaths can be edited using the buttons with the "up arrow" and "down arrow" icons.

Configure the Build Properties for the Modules

Java Module/EJB Module/Web Module on the Explore Panel > Right Click > Properties

Clicking on this brings up the Properties dialog box. Click on the Build tab to view and modify the following build settings:

Source Root Displays the source root of the Module. This field is not editable.

Output Dir Displays the target classes that have been built for folders. This field is editable only for Java Modules.

Example

A Desk comprises two folders - A and B, the target classes can be set such that the classesA files are stored under the B folder and the rest under A folder.

Main Class This field is not editable for Modules.

Compilation option The compilation options can be changed according the requirement. The compilation options available in the Build Settings are:

Classpath Comprises all the class paths that can be added and deleted from this dialog box. The user class paths for the Java Modules or EJB Modules are always added to the class path before the other user class paths of the Desk.

Classpath entries for module, which are not present in the classpath entries for the Desk are displayed with white background and black text. Entries in the classpath that do not exist in the file system are shown with white background and red text.

Creating a new module in the Desk sets the Class path of the module with the following information:

The order of the Classpaths can be edited using the buttons with the "up arrow" and "down arrow" icons.

Using the Build Tool

Compiling

Build > Compile

Compiles the selected file and displays all the errors in the output panel if any. For JSP Pages that use Taglib JARs to be compiled, the URL must point to the location of the taglib JAR being used.

Building

Build > Build

Builds the stipulated format by compiling all the files in the application. While building the files, it does not check for the dependencies, and therefore may not show all the compilation errors during compilation. It is faster than Clean Build.

All the errors and the warnings are displayed in the output panel. Right clicking on the appropriate node > Build also allows you to build the application.

Clean Building

Right Click on the specific folder > Right Click > Clean Build

Clean Build complies all the files contained in the folder where Clean Build is executed, while Build checks the time stamp of the class files and then compiles the files only if required. Compiling the files in this way takes longer than compiling the files using Build, but is more reliable.

Build is faster than Clean Build and is sufficient in most cases. If you have changed the interfaces, then Clean Build is advised as it compiles all the files and the errors are shows at compile time instead of runtime. All the errors and the warnings are displayed in the output panel.

Deleting files from the Desk deletes all the corresponding class files.

Building JAR, WARs and EARs

Right Click on JAR/WAR/EAR > Build

Building an archive compiles its contents and updates them. To know more on updation, read the chapter on Packaging.

Building Errors

In the Build tab of the Output window, place the cursor on the build error number and double click. This positions the cursor at the appropriate place in the display panel, and takes the user to the previous and next errors. The keyboard shortcuts for these are Ctrl + Shift + Z, and Ctrl + Shift + A respectively.

Stopping the Build Process

Build > Stop Build

Stops the Build process by stopping the currently executing tool. While the building process is on in the background, Studio can be used as usual.

Understanding how Build Tool Works

The Build tool compiles and recompiles and recreates files without the user having to remember what changed and in what order to compile the files. It also allows you to develop applications such that it is more portable, and on multiple platforms.

It is one of the most important tools in Studio. Without building files in an application, it cannot be deployed.

Before building the application, the settings for the same can be set. The class files are by default placed in the following locations:

Node in the Tree
Location
Desk
Studio/My Desk
Java Module
Studio/My Desk/classes/Java Module
EJB Module
Studio/My Desk/classes/EJB Module
Web Module
Studio/My Desk/Web Module/web-inf/classes

The user can change the default settings of the class files only for Java Modules. To understand how the build tool functions browse through the cases given below. These cases are implications of the Build tool rules.

Case 1

The Desk comprises one folder. The folder can either be a Java Module or an EJB Module. The location of the module in the file system is the same as that in the Desk. The Build tool, in such a case compiles all the files in the module and then builds the EJB Module or the Java Module with the specified build settings.

Example

In the screen-shot below, the left side displays the Desk tree structure where the Desk Bank has one EJB Module called - EJB Mod. The right side displays the source root of the module in the file system, which is in the same position as that of the module in the Desk. Here c:/pramati_studio represents the installation directory of Studio. The output classes directory is stored under c:/pramati_studio/Bank/classes/EJB Mod. This is not editable for an EJB Module.

Case 2

The Desk comprises two folders where one is a Java Module and the other is an EJB Module. Both the folders share the same source root in the disk. Both the Java Module and the EJB Module share one or more files/Beans.

The Build tool, in this case compiles a file/bean as many times as it has been added to the Desk. In the above scenario as the same file/bean is shared by both the folders, compiling the file/bean in one-folder compiles them in the other folder automatically. Compiling a bean also compiles the helper class. Once both the Java Module and EJB Module get built with the specified built settings, the EJB Module is ready to be deployed.

Example

In the screen-shot given below, the left side displays the Desk tree structure where the Desk Bank has one Java Module called - Java Mod and one EJB Module called - EJB Mod.

Both these files point to the same source root in the file system c:/pramati_studio/Bank/BankEJB. Both CheckingBean.java and Test.java get compiled twice as they exist in two modules. The output classes directory for the EJB

Module is stored in c:/pramati_studio/Bank/classes/EJB Mod and the output classes directory for the Java Module in c:/pramati_studio/Bank/classes/Java Mod. The output classes directory for the Java Module can be changed.

Case 3

The Desk comprises of two folders where one is a Java Module and the other is an EJB Module. Both the folders have different source roots in the disk. The files/Beans in one folder depends on the files/beans of the other folder. Both the Java Module and the EJB Module share a file/Bean.

In this case, the helper classes get picked up from the same source root automatically while building. Since the file/Bean, which is being depended on, do not belong to the same source root, it has to be explicitly added to the specific user class path. Both the Java Module and EJB Module then get built with the specified built settings and the EJB Module is ready to be deployed.


Pramati Technologies  © Copyright   TOCPREVNEXTINDEX