Pre-compiling model JSPs
In this Topic ...
Related Topics ...
Pre-generating and pre-compiling Java Server Pages (JSPs) prior to deployment eliminates the delay a user experiences due to the lag time caused by waiting for JSP pages to generate and compile. The JSP Pre-Compile tool provides a way for developers and deployment engineers to compile JSPs ahead of time. This tool is available from the command line.
How Pre-Compilation Works
The tool uses a two-stage approach to generating and compiling JSPs:
- Stage 1, Generation -- The tool examines all models and associated Profile Sets in a project. It then works through all possible combinations of those items to generate the JSPs associated with the model/Profile Set associations. The JSPs are saved to the server and a list of all JSPs generated is created.
- Stage 2, Compilation -- The tool next walks through the list of generated JSPs and forces a compile of each JSP in the list. Note that the server must be running in order for JSP compilation to be successful because the tool makes a HTTP request to the server requesting a specific JSP page with a pre-compile flag set for the page. Compiled JSP are stored in the Factory s .../genjsp directory.
Disabling JSP Security Required
The Factory creates all JSP in the .../genjsp directory in the Factory file system. By default, the Factory provides protection and security constraints on HTTP requests to this directory so that it is inaccessible to users of the application. However, for the JSP Pre-Compile tool to operate, the tool must be able to make HTTP requests to this directory.
In order to run the tool you will need to disable security on the /genjsp directory. How you do this depends on the application server you are using. Some app servers have administrative tools for editing security constraints. In any case, any <securiy-constraint> elements in the web.xml deployment descriptors that put restrictions on the /genjsp folder need to be temporarily removed until after this tool is run.
Because the JSP pre-compile tool makes HTTP calls the JSPs in the application server (with the precompile=true flag), the application server must be running in order for the pre-compile tool to work.
Pre-Compiling JSPs
You pre-compile JSPs from the command line. This process requires you to execute a compile command with one or more arguments. A script-based version of the JSP Pre-Compile tool is available as a Windows batch command and also as a UNIX script. The tool can accept several optional arguments that allow you to control how JSP generation and compilation is performed.
Compile scripts take the following arguments:
- -url - (required) This is the base URL for static files (HTML, JSP, etc.) on the server. This argument must include the application context. Typical syntax for this argument might looks as follows:
-url http://<serverName>:<port>/<appContext>/
- -modellist - (optional) Name of a file that lists the model IDs of the models you want examined. This file lists one ID per line and it can be created in any text editor. For example: factory/samples/tutorialFinished . If this argument is not supplied, all models are examined and associated JSPs compiled. Use this argument when you want to work with a subset of models in an application. Typical syntax for this argument looks as follows:
-modellist <listOfModels>.txt
- -profilelist - (optional) Name of a file that lists the profiles you want examined. This file lists one profile and Profile Set per line (for example, profile setBAR!profileFOO) and the file can be created in any text editor.
We can use this argument to limit the number of model/profile combinations that the pre-compile tool examines and generates This argument directs the tool to use only the specified profiles. (In addition, the default Profile Set is always used.) If this argument is not supplied, all model/profile combinations are examined and associated JSPs compiled. Typical syntax for this argument looks as follows:
-profilelist <listOfProfiles>.txt
A complete pre-compile command might look as follows:
compileJSP -url http://<serverName>:<port>/<appContext>/ -modellist <listOfModels>.txt -profilelist <listOfProfiles>.txt
Running the Pre-Compile Tool
Follow these steps to run the JSP pre-compile tool from the command line on DOS or UNIX:
- Disable security on the .../genjsp directory.
- Ensure that the application server is running.
- Change to the Factory's .../J2EERoot/bin directory.
- Type the following command: compilejsp.bat (on UNIX, compilejsp.sh)
- Type the URL argument.
- Type any other desired arguments.
- Press Enter to initiate operations.
- Examine the .../genjsp directory to view the generated JSPs.
Pre-Compiling JSPs in a Portlet WAR File
We can pre-compile JSPs associated with a portlet WAR file just as we can other JSPs. This allows you to improve performance by creating all the JSPs associated with a model in one operation. The process is similar to pre-compiling from the command line, however there are differences related to the URL used and other parameters.
To pre-compile JSPs located in a portlet WAR file:
- Deploy the portlet WAR file containing the JSPs you want to pre-compile.
- In the directory where the WAR file was deployed, locate the WEB-INF\bin directory.
- Generate a list of model files that you want JSPs pre-compiled for. This list will serve as an argument to the pre-compile command and must be in the proper format. (See section above that describes -modellist argument. )
- Note the URL to be used as an argument to the pre-compile command. This URL must include the name of the portlet adaptor WAR file. Type the following command to initiate compilation:
compileJSP -modellist c:/model.txt -url http://your.machine.name/<portal-server-specific path>/<portlet adapter WAR filename>
- Press Enter to initiate operations.
- Examine the .../genjsp directory to view the generated JSPs.