Thursday, February 7, 2013

Precompile JSF 1.1 pages on Weblogic 12c

Even after adding only JSF 1.1 jars  on compile classpath of wlappc the generated java classes are not running correctly on Weblogic 12c. There seems to be problem with classpath of wlappc which is not respecting filtering classloader of weblogic.xml descriptor.

Problem can be solved by adding precompile to jsp-descriptor element of weblogic.xml 


precompile
 
When set to true, WebLogic Server automatically precompiles all modified JSPs when the Web application is deployed or re-deployed or when starting WebLogic Server


precompile-continue
 
When set to true, WebLogic Server continues precompiling all modified JSPs even if some of those JSPs fail during compilation. Only takes effect when precompile is set to true.



Weblogic appc
http://docs.oracle.com/cd/E24329_01/web.1211/e24973/appc_ejbc.htm

Add option to check class loading
 http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/java.html

-verbose:class
Display information about each class loaded.


JSP page
<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<f:view>
<f:loadBundle basename="resources.application" var="msg"/>
<html>
<head>
  <title><h:outputText value="#{msg.welcomeTitle}" /></title>
</head>
<body>

<h3><h:outputText value="#{msg.welcomeHeading}" /></h3>

<p><h:outputText value="#{msg.welcomeMessage}" /></p>

</body>
</html>
</f:view>



Compile using MyFaces libs in WEB-INF/lib
[dave@dave config]$ java weblogic.appc -verboseJavac -verbose ~/workspace/testFSF11/WebContent/
[JspcInvoker]Checking web app for compliance.
<Feb 6, 2013 11:39:24 PM CET> <Info> <HTTP> <BEA-101047> <[ComplianceChecker] Validating the servlet element with servlet-name named "Faces Servlet".> 
<Feb 6, 2013 11:39:24 PM CET> <Info> <HTTP> <BEA-101047> <[ComplianceChecker] Checking servlet-mapping for servlet name : "Faces Servlet".> 
[jspc]  -webapp specified, searching . for JSPs
[jspc] Compiling /index.jsp
<Feb 6, 2013 11:39:29 PM CET> <Info> <J2EE> <BEA-160220> <Compilation completed successfully.> 

Alternative ant script

<project name="Appc" default="appc" basedir="./">

    <property environment="env"/>

    <target name="appc" description="Packages the WAR file">
        <!-- Precompile JSP pages using appc -->
        <echo message="Precompile JSP pages using appc in WebContent" />
        <path id="wlappc.classpath">
            <fileset dir="${env.WL_HOME}/server/lib">
                <include name="weblogic.jar" />
            </fileset>
        </path>
        <path id="compile.classpath">
            <fileset dir="WebContent/WEB-INF/lib">
                <include name="*.jar" />
            </fileset>
        </path>

        <echo message="${toString:wlappc.classpath}" />
        <echo message="${toString:compile.classpath}" />
        <taskdef name="wlappc" classname="weblogic.ant.taskdefs.j2ee.Appc"
            classpathref="wlappc.classpath" />
        <wlappc verbose="true" keepGenerated="true" source="WebContent"
            verboseJavac="true"
            classpathref="compile.classpath">

        </wlappc>

    </target>


[dave@dave testFSF11]$ ant 
Buildfile: build.xml

appc:
     [echo] Precompile JSP pages using appc in WebContent
     [echo] /opt/weblogic/wlserver_12.1/server/lib/weblogic.jar
     [echo] /home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-beanutils-1.7.0.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-collections-3.1.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-digester-1.8.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-el-1.0.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-lang-2.1.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-logging-1.1.1.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/jstl-1.1.0.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/myfaces-api-1.1.10.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/myfaces-impl-1.1.10.jar
   [wlappc] [JspcInvoker]Checking web app for compliance.
   [wlappc] <Feb 6, 2013 11:51:12 PM CET> <Info> <HTTP> <BEA-101047> <[ComplianceChecker] Validating the servlet element with servlet-name named "Faces Servlet".> 
   [wlappc] <Feb 6, 2013 11:51:12 PM CET> <Info> <HTTP> <BEA-101047> <[ComplianceChecker] Checking servlet-mapping for servlet name : "Faces Servlet".> 
   [wlappc] [jspc] Overriding descriptor option 'keepgenerated' with value specified on command-line 'true' 
   [wlappc] [jspc]  -webapp specified, searching . for JSPs
   [wlappc] [jspc] Compiling /index.jsp
   [wlappc] <Feb 6, 2013 11:51:18 PM CET> <Info> <J2EE> <BEA-160220> <Compilation completed successfully.> 

BUILD SUCCESSFUL
Total time: 10 seconds



Compile using JSF 1.2 deployable library

[dave@dave testJSF1]$ java weblogic.appc -keepGenerated  -verboseJavac -verbose -library /opt/weblogic/wlserver_12.1/common/deployable-libraries/jsf-1.2.war  WebContent/
<Feb 7, 2013 12:52:28 AM CET> <Info> <J2EE> <BEA-160151> <Registered library Extension-Name: jsf, Specification-Version: 1.2, Implementation-Version: 1.2.9.0 (WAR).> 
Unresolved WebApp library references defined in weblogic.xml, of module 'WebContent' [Extension-Name: jstl, Specification-Version: 1.2, exact-match: true]
[dave@dave testJSF1]$ java weblogic.appc -keepGenerated  -verboseJavac -verbose -library /opt/weblogic/wlserver_12.1/common/deployable-libraries/jsf-1.2.war,/opt/weblogic/wlserver_12.1/common/deployable-libraries/jstl-1.2.war  WebContent/
<Feb 7, 2013 12:53:07 AM CET> <Info> <J2EE> <BEA-160151> <Registered library Extension-Name: jsf, Specification-Version: 1.2, Implementation-Version: 1.2.9.0 (WAR).> 
<Feb 7, 2013 12:53:07 AM CET> <Info> <J2EE> <BEA-160151> <Registered library Extension-Name: jstl, Specification-Version: 1.2, Implementation-Version: 1.2.0.2 (WAR).> 
[JspcInvoker]Checking web app for compliance.
<Feb 7, 2013 12:53:10 AM CET> <Info> <HTTP> <BEA-101047> <[ComplianceChecker] Validating the servlet element with servlet-name named "Faces Servlet".> 
<Feb 7, 2013 12:53:10 AM CET> <Info> <HTTP> <BEA-101047> <[ComplianceChecker] Checking servlet-mapping for servlet name : "Faces Servlet".> 
[jspc] Overriding descriptor option 'keepgenerated' with value specified on command-line 'true' 
[jspc]  -webapp specified, searching . for JSPs
[jspc] Compiling /index.jsp
<Feb 7, 2013 12:53:14 AM CET> <Info> <J2EE> <BEA-160220> <Compilation completed successfully.> 

Difference between MyFaces and JSF 1.2 compilation

[dave@dave workspace]$ diff testJSF1/WebContent/WEB-INF/classes/jsp_servlet/__index.java testFSF11/WebContent/WEB-INF/classes/jsp_servlet/__index.java
32c32
<         if (sci.isResourceStale("/index.jsp", 1359883373000L ,"12.1.1.0","Europe/Bratislava")) return true;
---
>         if (sci.isResourceStale("/index.jsp", 1359886357000L ,"12.1.1.0","Europe/Bratislava")) return true;
105c105
<          com.sun.faces.taglib.jsf_core.ViewTag __tag0 = null ;
---
>          org.apache.myfaces.taglib.core.ViewTag __tag0 = null ;
109c109
<             __tag0 = new  com.sun.faces.taglib.jsf_core.ViewTag ();
---
>             __tag0 = new  org.apache.myfaces.taglib.core.ViewTag ();
116d115
<         __tag0.setJspId("id0");
165c164
<     private boolean _jsp__tag1(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, com.sun.faces.taglib.jsf_core.ViewTag parent) throws java.lang.Throwable
---
>     private boolean _jsp__tag1(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, org.apache.myfaces.taglib.core.ViewTag parent) throws java.lang.Throwable
170c169
<          com.sun.faces.taglib.jsf_core.LoadBundleTag __tag1 = null ;
---
>          org.apache.myfaces.taglib.core.LoadBundleTag __tag1 = null ;
174c173
<             __tag1 = new  com.sun.faces.taglib.jsf_core.LoadBundleTag ();
---
>             __tag1 = new  org.apache.myfaces.taglib.core.LoadBundleTag ();
179c178
<         __tag1.setBasename( weblogic.servlet.jsp.ELHelper.createValueExpression("resources.application",java.lang.String.class,pageContext,_jspx_fnmap));
---
>         __tag1.setBasename(( java.lang.String) weblogic.jsp.internal.jsp.utils.JspRuntimeUtils.convertType("resources.application", java.lang.String.class,"basename"));
186c185
<                  throw  new  javax.servlet.jsp.JspTagException("Since tag class com.sun.faces.taglib.jsf_core.LoadBundleTag does not implement BodyTag, it cannot return BodyTag.EVAL_BODY_BUFFERED");
---
>                  throw  new  javax.servlet.jsp.JspTagException("Since tag class org.apache.myfaces.taglib.core.LoadBundleTag does not implement BodyTag, it cannot return BodyTag.EVAL_BODY_BUFFERED");
200c199
<     private boolean _jsp__tag2(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, com.sun.faces.taglib.jsf_core.ViewTag parent) throws java.lang.Throwable
---
>     private boolean _jsp__tag2(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, org.apache.myfaces.taglib.core.ViewTag parent) throws java.lang.Throwable
205c204
<          com.sun.faces.taglib.html_basic.OutputTextTag __tag2 = null ;
---
>          org.apache.myfaces.taglib.html.HtmlOutputTextTag __tag2 = null ;
209c208
<             __tag2 = new  com.sun.faces.taglib.html_basic.OutputTextTag ();
---
>             __tag2 = new  org.apache.myfaces.taglib.html.HtmlOutputTextTag ();
214,215c213
<         __tag2.setJspId("id2");
<         __tag2.setValue( weblogic.servlet.jsp.ELHelper.createValueExpression("#{msg.welcomeTitle}",java.lang.Object.class,pageContext,_jspx_fnmap));
---
>         __tag2.setValue(( java.lang.String) weblogic.jsp.internal.jsp.utils.JspRuntimeUtils.convertType("#{msg.welcomeTitle}", java.lang.String.class,"value"));
220a219
>                  throw  new  javax.servlet.jsp.JspTagException("Since tag class org.apache.myfaces.taglib.html.HtmlOutputTextTag does not implement BodyTag, it cannot return BodyTag.EVAL_BODY_BUFFERED");
234c233
<     private boolean _jsp__tag3(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, com.sun.faces.taglib.jsf_core.ViewTag parent) throws java.lang.Throwable
---
>     private boolean _jsp__tag3(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, org.apache.myfaces.taglib.core.ViewTag parent) throws java.lang.Throwable
239c238
<          com.sun.faces.taglib.html_basic.OutputTextTag __tag3 = null ;
---
>          org.apache.myfaces.taglib.html.HtmlOutputTextTag __tag3 = null ;
243c242
<             __tag3 = new  com.sun.faces.taglib.html_basic.OutputTextTag ();
---
>             __tag3 = new  org.apache.myfaces.taglib.html.HtmlOutputTextTag ();
248,249c247
<         __tag3.setJspId("id3");
<         __tag3.setValue( weblogic.servlet.jsp.ELHelper.createValueExpression("#{msg.welcomeHeading}",java.lang.Object.class,pageContext,_jspx_fnmap));
---
>         __tag3.setValue(( java.lang.String) weblogic.jsp.internal.jsp.utils.JspRuntimeUtils.convertType("#{msg.welcomeHeading}", java.lang.String.class,"value"));
254a253
>                  throw  new  javax.servlet.jsp.JspTagException("Since tag class org.apache.myfaces.taglib.html.HtmlOutputTextTag does not implement BodyTag, it cannot return BodyTag.EVAL_BODY_BUFFERED");
268c267
<     private boolean _jsp__tag4(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, com.sun.faces.taglib.jsf_core.ViewTag parent) throws java.lang.Throwable
---
>     private boolean _jsp__tag4(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, org.apache.myfaces.taglib.core.ViewTag parent) throws java.lang.Throwable
273c272
<          com.sun.faces.taglib.html_basic.OutputTextTag __tag4 = null ;
---
>          org.apache.myfaces.taglib.html.HtmlOutputTextTag __tag4 = null ;
277c276
<             __tag4 = new  com.sun.faces.taglib.html_basic.OutputTextTag ();
---
>             __tag4 = new  org.apache.myfaces.taglib.html.HtmlOutputTextTag ();
282,283c281
<         __tag4.setJspId("id4");
<         __tag4.setValue( weblogic.servlet.jsp.ELHelper.createValueExpression("#{msg.welcomeMessage}",java.lang.Object.class,pageContext,_jspx_fnmap));
---
>         __tag4.setValue(( java.lang.String) weblogic.jsp.internal.jsp.utils.JspRuntimeUtils.convertType("#{msg.welcomeMessage}", java.lang.String.class,"value"));
288a287
>                  throw  new  javax.servlet.jsp.JspTagException("Since tag class org.apache.myfaces.taglib.html.HtmlOutputTextTag does not implement BodyTag, it cannot return BodyTag.EVAL_BODY_BUFFERED");


Check from where are classed loaded
[dave@dave jsf-blank-myfaces]$ java -verbose:class weblogic.appc -keepGenerated  -verboseJavac -verbose -library /opt/weblogic/wlserver_12.1/common/deployable-libraries/jsf-1.2.war,/opt/weblogic/wlserver_12.1/common/deployable-libraries/jstl-1.2.war  WebContent/ > classloader.log


weblogic.appc
[dave@dave jsf-blank-myfaces]$ grep appc classloader.log 
[Loaded weblogic.appc from file:/opt/weblogic/wlserver_12.1/server/lib/weblogic.jar]


myfaces
[Loaded javax.faces.webapp.FacesServlet from file:/home/dave/app/jsf-blank-myfaces/WebContent/WEB-INF/lib/myfaces-api-1.1.5.jar]


Extract appc class

[dave@dave jsf-blank-myfaces]$ jar tvf /opt/weblogic/wlserver_12.1/server/lib/weblogic.jar |grep -i appc
  2091 Wed Dec 07 08:42:12 CET 2011 weblogic/management/configuration/WebAppContainerMBean.class
 19320 Wed Dec 07 08:45:18 CET 2011 weblogic/management/configuration/WebAppContainerMBeanImpl.class
 13336 Wed Dec 07 08:45:18 CET 2011 weblogic/management/configuration/WebAppContainerMBeanImpl$Helper.class
  9673 Wed Dec 07 08:47:18 CET 2011 weblogic/ant/taskdefs/j2ee/Appc.class
   479 Wed Dec 07 08:43:08 CET 2011 weblogic/appc.class

[dave@dave jsf-blank-myfaces]$ jar xvf /opt/weblogic/wlserver_12.1/server/lib/weblogic.jar weblogic/ant/taskdefs/j2ee/Appc.class
 inflated: weblogic/ant/taskdefs/j2ee/Appc.class

Disassemble class files using javap
 

[dave@dave jsf-blank-myfaces]$ javap  weblogic/ant/taskdefs/j2ee/Appc.class
Compiled from "Appc.java"
public class weblogic.ant.taskdefs.j2ee.Appc extends weblogic.ant.taskdefs.j2ee.CompilerTask {
  public weblogic.ant.taskdefs.j2ee.Appc();
  public void setClasspath(java.lang.String);
  public void setSource(java.lang.String);
  public void setOutput(java.lang.String);
  public void setForceGeneration(boolean);
  public void setLineNumbers(boolean);
  public void setBasicClientJar(boolean);
  public void setContinueCompilation(boolean);
  public void setVerbose(boolean);
  public void setEnableHotCodeGen(boolean);
  public void setIiopDirectory(java.lang.String);
  public void setIdlDirectory(java.lang.String);
  public void setIdl(boolean);
  public void setIdlOverwrite(boolean);
  public void setIdlVerbose(boolean);
  public void setIdlNoValueTypes(boolean);
  public void setIdlNoAbstractInterfaces(boolean);
  public void setIdlFactories(boolean);
  public void setIdlVisibroker(boolean);
  public void setIdlOrbix(boolean);
  public void setIiop(boolean);
  public void setIdlMethodSignatures(java.lang.String);
  public void setlibraryDir(java.lang.String);
  public void setPlan(java.lang.String);
  public void setClientJarOutputDir(java.lang.String);
  public void addConfiguredLibrary(weblogic.ant.taskdefs.utils.LibraryElement);
  public void execute();
}

1 comment: