ProblemYou want to precompile a JSP in WebLogic. SolutionUse the weblogic.jspc Java utility that installs with WebLogic Server 7.0. DiscussionWebLogic Server 7.0 installs with its own Java utility for precompiling JSPs: weblogic.jspc . This utility is part of the JAR file that can be found at this location: <WebLogic-install-directory>/weblogic700/server/lib/weblogic.jar . When you precompile JSPs using weblogic.jspc , it places the class files in the specified destination directory. Example 5-4 shows a simple batch file on Windows NT that precompiles an example.jsp JSP page into its servlet implementation class. Example 5-4. Precompiling a JSP with weblogic.jspc@echo off set WLCLASSPATH=k:\bea\weblogic700\server\lib\weblogic.jar;%CLASSPATH% java -cp %WLCLASSPATH% weblogic.jspc -d .\classes example.jsp The second line of Example 5-4 sets an environment variable, WLCLASSPATH . This variable prepends a reference to weblogic.jar to the existing CLASSPATH variable. The next line of the example uses this combined classpath to run weblogic.jspc . The -d switch tells the program where to store the resulting class files, in this case, in the classes directory beneath the directory containing the batch file and example.jsp . This program generates a Java class file named jsp_servlet._ _example.class (including the package name ). If you do not specify a package for the compiled servlet, jsp_servlet is used as the default package name (see Example 5-6). Example 5-5 shows a shell script that is written on Mac OS X for precompiling a JSP with WebLogic. Example 5-5. Precompiling JSPs with weblogic.jspc and a shell script#!/bin/sh WLCLASSPATH=/Users/bruceper/java/weblogic_jar/weblogic.jar:$CLASSPATH; export WLCLASSPATH; java -cp $WLCLASSPATH weblogic.jspc -d /Users/bruceper/books/cookbook/code/chap5/classes newfile.jsp
The Windows batch file in Example 5-6 specifies a jspservletcookbook package for all the JSP pages found in the web application specified by the -webapp switch. Example 5-6. Using weblogic.jspc to precompile all JSP pages in a web application@echo off set WLCLASSPATH=k:\bea\weblogic700\server\lib\weblogic.jar;%CLASSPATH% java -cp %WLCLASSPATH% weblogic.jspc -d .\classes -package jspservletcookbook -compileAll -webapp h:/home Example 5-7 shows a Unix shell script that does the same thing. Example 5-7. Precompiling all JSP pages in a web application with a shell script#!/bin/sh WLCLASSPATH=/Users/bruceper/java/weblogic_jar/weblogic.jar:$CLASSPATH; export WLCLASSPATH; java -cp $WLCLASSPATH weblogic.jspc -d /Users/bruceper/books/cookbook/code/chap5/classes -package jspservletcookbook -compileAll -webapp /Users/bruceper/books/cookbook/code/chap5 Note this portion of the instruction in the example: -compileAll -webapp h:/home The -compileAll switch, along with an argument to -webapp , tells weblogic.jspc to precompile all the JSP files found in the web application configured in the h:\home directory, including any JSP files nested in subdirectories. This web application is in exploded directory format (not archived into a WAR file). In Example 5-6, the compiled classes are stored in the \classes\jspservletcookbook directory path . See AlsoRecipe 5.3 on the precompilation protocol; Recipe 5.4 on mapping the compiled JSP(s) in web.xml ; the JSP precompilation section of JavaServer Pages by Hans Bergsten (O'Reilly); Chapter JSP.11.4 of the JSP 2.0 specification. |