Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to precompile JSPs using Ant

Tags:

java

jsp

oracle

ant

I am trying to figure out the best way to use Ant to precompile JSPs that will be deployed to an Oracle application server. Even though I am deploying to an Oracle app server I would like to avoid using Oracle's version of Ant.

like image 387
rich Avatar asked Oct 23 '08 14:10

rich


2 Answers

Oracle's JSP compiler is available in your oc4j install at ORACLE_HOME/j2ee/home/jsp/bin/ojspc

Assuming your classpath is correct at the compand line you would run:

ojspc your.war

The war will get updated and place a jar in the WEB-INF/lib containing the pre-compiled JSPs. Note that if your pre-compiling JSPs you should also set the MAIN_MODE to 'JUSTRUN' to get the additional performance benefit of pre-compiling your JSPs. The JUSTRUN setting does what it implies, the OC4J container will no longer check for updated .jsp files.

<servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>oracle.jsp.runtimev2.JspServlet</servlet-class>
    <init-param>
      <param-name>main_mode</param-name>
      <param-value>justrun</param-value>
    </init-param>
</servlet>

Once your comfortable with calling ojspc from the command line You can then begin to use the ANT tasks provided by Oracle.

Within ANT

<oracle:compileJsp file="dist/war/before-${app}war"
        verbose="false"
        output="dist/war/${app}.war" />

Your project tag should reference the oracle tasks:

<project name="your-name" default="compile" basedir="."  xmlns:oracle="antlib:oracle">
...
</project>

Update 02.22.2011 You can also just work with the ojspc jar directly and avoid trying to configure the oracle:compileJsp Task, the code below takes a war file and pre-compiles the JSPS in it.

 <!-- Now Precompile the War File (see entry in <project> tag ) -->
    <java jar="${env.ORACLE_HOME}/j2ee/home/ojspc.jar" classpathref="jspPreCompileClassPath" fork="true">
        <arg value="-addClasspath"/>
        <arg pathref="classpath"/>
        <arg line="'${dist}/war/a-war-file.war'"/>
    </java>

the jspPreCompileClassPath defnition looks like this:

  <path id="jspPreCompileClassPath">
    <path location="${env.ORACLE_HOME}/j2ee/home/lib/pcl.jar"/>
    <path location="${env.ORACLE_HOME}/j2ee/home/lib/ojsp.jar"/>
    <path location="${env.ORACLE_HOME}/j2ee/home/lib/oc4j-internal.jar"/>
    <path location="${env.ORACLE_HOME}/j2ee/home/lib/servlet.jar"/>
    <path location="${env.ORACLE_HOME}/j2ee/home/lib/commons-el.jar"/>
    <path location="${env.ORACLE_HOME}/j2ee/home/lib/bcel.jar"/>
    <path location="${env.ORACLE_HOME}/lib/xmlparserv2.jar"/>
    <path location="${env.ORACLE_HOME}/j2ee/home/lib/oc4j-schemas.jar"/>
    <path location="${env.ORACLE_HOME}/j2ee/home/jsp/lib/taglib/ojsputil.jar"/>
  </path>
like image 191
Brian Avatar answered Oct 15 '22 12:10

Brian


I'm not sure what you mean by Oracle's version of Ant but as I understand it you will need the oracle's ant task to do this job. This page explains how to do it. You will be using the apache ant that you download from the apache website, but you need to use Oracle ant task library from Oracle to pre compile JSPs for Oracle.

like image 39
Vincent Ramdhanie Avatar answered Oct 15 '22 12:10

Vincent Ramdhanie