Sunday, January 14, 2007

Using the WebLogic JSP Compiler

Using the WebLogic JSP Compiler

Because the JSP Servlet automatically calls the WebLogic JSP compiler to process your JSP pages, you generally do not need to use the compiler directly. However, in some situations, such as when you are debugging, accessing the compiler directly is useful. This section is a reference for the compiler.

The WebLogic JSP compiler parses your JSP file into a .java file, and then compiles the generated .java file into a Java class, using a standard Java compiler.

Running JSPC on Windows Systems

When you run the JSP compiler on Windows systems, output files names are always created with lower case names. To prevent this behavior, and preserve the case used in class names, set the system property, weblogic.jsp.windows.caseSensitive to true. You can set the property at the command line when compiling a JSP using this following command:

java -Dweblogic.jsp.windows.caseSensitive=true weblogic.jspc *.jsp

or include this command in your WebLogic Server startup scripts:

-Dweblogic.jsp.windows.caseSensitive=true

JSP Compiler Syntax

The JSP compiler works in much the same way that other WebLogic compilers work (including the RMI and EJB compilers). To start the JSP compiler, enter the following command.

$ java weblogic.jspc -options fileName

Replace fileName with the name of the JSP file that you want to compile. You can specify any options before or after the target fileName. The following example uses the -d option to compile myFile.jsp into the destination directory, weblogic/classes:

$ java weblogic.jspc -d /weblogic/classes myFile.jsp

Note: If you are precompiling JSPs that are part of a Web Application and that reference resources in the Web Application (such as a JSP tag library), you must use the -webapp flag to specify the location of the Web Application. The -webapp flag is described in the following listing of JSP compiler options.

JSP Compiler Options

You can use any combination of the following options:

-classpath

Add a list (separated by semi-colons on Windows NT/2000 platforms or colons on UNIX platforms) of directories that make up the desired CLASSPATH. Include directories containing any classes required by the JSP. For example (to be entered on one line):

$ java weblogic.jspc

-classpath java/classes.zip;/weblogic/classes.zip

myFile.JSP

-charsetMap

Specifies mapping of IANA or unofficial charset names used in JSP contentType directives to java charset names. For example:

-charsetMap x-sjis=Shift_JIS,x-big5=Big5

The most common mappings are built into the JSP compiler. Use this option only if a desired charset mapping is not recognized.

-commentary

Causes the JSP compiler to include comments from the JSP in the generated HTML page. If this option is omitted, comments do not appear in the generated HTML page.

-compileAll

Recursively compiles all JSPs in the current directory, or in the directory specified with the -webapp flag. (See the listing for -webapp in this list of options.). JSPs in subdirectories are also compiled.

-compileFlags

Passes one or more command-line flags to the compiler. Enclose multiple flags in quotes, separated by a space. For example:

java weblogic.jspc -compileFlags "-g -v" myFile.jsp

-compiler

Specifies the Java compiler to be used to compile the class file from the generated Java source code. The default compiler used is javac. The Java compiler program should be in your PATH unless you specify the absolute path to the compiler explicitly.

-compilerclass

Runs a Java compiler as a Java class and not as a native executable.

-compilerSupportsEncoding

Specifies that the compiler used supports encoding such as that used by other compilers.

-d

Specifies the destination of the compiled output (that is, the class file). Use this option as a shortcut for placing the compiled classes in a directory that is already in your CLASSPATH.

-depend

If a previously generated class file for a JSP has a more recent date stamp than the JSP source file, the JSP is not recompiled.

-debug

Compile with debugging on.

-deprecation

Warn about the use of deprecated methods in the generated Java source file when compiling the source file into a class file.

-docroot directory

See -webapp.

-encoding default|named character encoding

Valid arguments include (a) default which specifices using the default character encoding of your JDK, (b) a named character encoding, such as 8859_1. If the -encoding flag is not specified, an array of bytes is used.

-g

Instructs the Java compiler to include debugging information in the class file.

-help

Displays a list of all the available flags for the JSP compiler.

-J

Takes a list of options that are passed to your compiler.

-k

When compiling multiple JSPs with with a single command, the compiler continues compiling even if one or more of the JSPs failed to compile.

-keepgenerated

Keeps the Java source code files that are created as an intermediary step in the compilation process. Normally these files are deleted after compilation.

-noTryBlocks

If a JSP file has numerous or deeply nested custom JSP tags and you receive a java.lang.VerifyError exception when compiling, use this flag to allow the JSPs to compile correctly.

-nowarn

Turns off warning messages from the Java compiler.

-noPrintNulls

Shows "null" in jsp expressions as "".

-O

Compiles the generated Java source file with optimization turned on. This option overrides the -g flag.

-package packageName

Sets the package name that is prepended to the package name of the generated Java HTTP servlet. Defaults to jsp_servlet.

-superclass classname

Sets the classname of the superclass extended by the generated servlet. The named superclass must be a derivative of HttpServlet or GenericServlet.

-verbose

Passes the verbose flag to the Java compiler specified with the compiler flag. See the compiler documentation for more information. The default is off.

-verboseJavac

Prints messages generated by the designated JSP compiler.

-version

Prints the version of the JSP compiler.

-webapp directory

Name of a directory containing a Web Application in exploded directory format. If your JSP contains references to resources in a Web Application such as a JSP tag library or other Java classes, the JSP compiler will look for those resources in this directory. If you omit this flag when compiling a JSP that requires resources from a Web Application, the compilation will fail.

Precompiling JSPs

You can configure WebLogic Server to precompile your JSPs when a Web Application is deployed or re-deployed or when WebLogic Server starts up by setting the precompile parameter to true in the element of the weblogic.xml deployment descriptor. To avoid recompiling your JSPs each time the server restarts and when you target additional servers, precompile them using weblogic.jspc and place them in the WEB-INF/classes folder and archive them in a .war file. Keeping your source files in a separate directory from the archived .war file will eliminate the possibility of errors caused by a JSP having a dependency on one of the class files.

For more information on the web.xml deployment descriptor, see Assembling and Configuring Web Applications.

Java Server Pages that are contained within a .war file can be precompiled using appc rather than weblogic.jspc. For additional information on using appc, see appc at Windows NT command length limitations can be overcome using the new compilerclass option for WebLogic JSPs. It can be configured in the weblogic.xml file.

The in memory compilerclass option uses the compiler class used by Sun to internally compile Java files. This does not require creating a new process and thus is more efficient than compiling each Java file separately using a new process.

The compilerclass can be used by adding the following to weblogic.xml:

  
   compilerclass
   com.sun.tools.javac.Main
 

Another way to prevent your JSPs from recompiling is to use the JSPClassServlet in place of JSPServlet and to place your precompiled JSPs into the WEB-INF/classes directory. This will remove any possibility of the JSPs being recompiled, as the server will not look at the source code. The server will not note any changes to the JSPs and recompile them if you choose this option. This option allows you to completely remove the JSP source code from your application after precompiling.

This is an example of how to add the JSPClassServlet to your Web Application's web.xml file.

JSPClassServlet

weblogic.servlet.JSPClassServlet

JSPClassServlet

*.jsp

As when using virtual hosting, you must have physical directories that correspond to the mappings you create to allow your files to be found by the server.

Increasing JSP Performance and Best Practices

If you have precompiled your JSPs, the precompile parameter should be set to false.

  1. Compile your JSPs using weblogic.jspc.
  1. Put your compiled JSP classes into their proper locations under the WEB-INF/classes directory of your web application. If you use the default package name, then your classes should all be under WEB-INF/classes/jsp_servlet i.e. if you have login.jsp, then it should be located under WEB-INF/classes/jsp_servlet/login.class
  1. Create or edit the weblogic.xml file for your web application following the instructions found in Developing Web Applications for WebLogic Server.
  1. In the jsp-descriptor element make sure you have set the following two parameters:

precompile

false

pageCheckSeconds

-1

When optimizing for speed, increase pageCheckSeconds to 10, 20 or 30+ seconds by determining how many times your JSPs will change during the day and setting the parameter appropriately.

  1. Archive your web application into a WAR.
  1. Deploy your web application.

0 Comments:

Post a Comment

<< Home