You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Marcus Beyer <mb...@stormlight.de> on 2005/01/14 15:57:51 UTC

precompilation trouble

Greetings!

Using Tomcat 5.0.26 I have some problems precompiling my pages with:

       org.apache.jasper.JspC

The precompiler instantiates some beans, altough I don't exactly know 
why. During instatiation some beans need to access managed beans, so 
they call something like this:

       FacesContext facesContext = FacesContext.getCurrentInstance ( );
       /*
        * this happens if I try to precompile some jsp pages ...
        */
       if (facesContext == null) log.error ("no faces context found!");
       Application app = facesContext.getApplication ( );
       Object o = app.createValueBinding ("#{" + beanName + 
"}").getValue (facesContext);

Unfortunately getCurrentInstance returns null causing the precompilation 
to fail.

Please help a bloody beginner :)

thanx!
Marcus

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: precompilation trouble

Posted by Marcus Beyer <mb...@stormlight.de>.
Marcus Beyer schrieb:

> The precompiler instantiates some beans, altough I don't exactly know 
> why. During instatiation some beans need to access managed beans, so 
> they call something like this:
> 
>       FacesContext facesContext = FacesContext.getCurrentInstance ( );
>       /*
>        * this happens if I try to precompile some jsp pages ...
>        */
>       if (facesContext == null) log.error ("no faces context found!");

I forgot to mention that I am using JSF 1.1_01 reference impl.

Has anyone an idea what is happening here? Please give me a hint.

thanx!
Marcus

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: precompilation trouble

Posted by Marcus Beyer <mb...@stormlight.de>.
Tim Funk schrieb:

> Oops, my bad. Forget newInstance() being called. But the line:
> Class bean = ctxt.getClassLoader().loadClass(klass);
> 
> I believe does force my previous static statements to hold true.

The problem was not during static initalizations but during 
instantiation of the beans. I solved that by checking if the faces 
context is null and then returning immediately in the constructor.

The next problem is: The resulting java code Japser produces is not 
compilable. Trying to compile these .java files results in lots of 
errors, e.g.:

The method _jspx_meth_c_set_4(JspTag, PageContext) in the type 
dayWeekView_jsp is not applicable for the arguments (IfTag, PageContext)

The other errors look quite similar. Any idea?

thanx!
Marcus


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: precompilation trouble

Posted by Tim Funk <fu...@joedog.org>.
Oops, my bad. Forget newInstance() being called. But the line:
Class bean = ctxt.getClassLoader().loadClass(klass);

I believe does force my previous static statements to hold true.

-Tim

Marcus Beyer wrote:

> Tim Funk schrieb:
> 
>> Ahh. Here is your issue:
>>
>> if (beanName == null) {
>>     try {
>>         Class bean = ctxt.getClassLoader().loadClass(klass);
>>         int modifiers = bean.getModifiers();
>>         if (!Modifier.isPublic(modifiers) ||
>>             Modifier.isInterface(modifiers) ||
>>             Modifier.isAbstract(modifiers)) {
>>             throw new Exception("Invalid bean class modifier");
>>         }
>>         // Check that there is a 0 arg constructor
>>         bean.getConstructor(new Class[] {});
>>         generateNew = true;
>>     } catch (Exception e) {
>>         // Cannot instantiate the specified class
>>         if (ctxt.getOptions().getErrorOnUseBeanInvalidClassAttribute()) {
>>             err.jspError(n, "jsp.error.invalid.bean", klass);
>>         }
>>     }
>> }
>>
>> At compile time - jasper is checking that the default constructor of a 
>> bean may be invoked. By invoking the constructor at compile time - the 
>> class is loaded by the JVM. This will in turn cause the JVM to call 
>> any static initializers. (In which you have)
> 
> 
> Hmm, were is that code is an invokation of a constructor? As far as I 
> can see Jasper just checks if a zero argument constructor exists.
> 
> And why does Jasper instantiate beans? Just to check if it is possible 
> to instantiate them, or does Jasper do something with the beans?
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: precompilation trouble

Posted by Marcus Beyer <mb...@stormlight.de>.
Tim Funk schrieb:

> Ahh. Here is your issue:
> 
> if (beanName == null) {
>     try {
>         Class bean = ctxt.getClassLoader().loadClass(klass);
>         int modifiers = bean.getModifiers();
>         if (!Modifier.isPublic(modifiers) ||
>             Modifier.isInterface(modifiers) ||
>             Modifier.isAbstract(modifiers)) {
>             throw new Exception("Invalid bean class modifier");
>         }
>         // Check that there is a 0 arg constructor
>         bean.getConstructor(new Class[] {});
>         generateNew = true;
>     } catch (Exception e) {
>         // Cannot instantiate the specified class
>         if (ctxt.getOptions().getErrorOnUseBeanInvalidClassAttribute()) {
>             err.jspError(n, "jsp.error.invalid.bean", klass);
>         }
>     }
> }
> 
> At compile time - jasper is checking that the default constructor of a 
> bean may be invoked. By invoking the constructor at compile time - the 
> class is loaded by the JVM. This will in turn cause the JVM to call any 
> static initializers. (In which you have)

Hmm, were is that code is an invokation of a constructor? As far as I 
can see Jasper just checks if a zero argument constructor exists.

And why does Jasper instantiate beans? Just to check if it is possible 
to instantiate them, or does Jasper do something with the beans?

thanx!
Marcus

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: precompilation trouble

Posted by Tim Funk <fu...@joedog.org>.
Ahh. Here is your issue:

if (beanName == null) {
     try {
         Class bean = ctxt.getClassLoader().loadClass(klass);
         int modifiers = bean.getModifiers();
         if (!Modifier.isPublic(modifiers) ||
             Modifier.isInterface(modifiers) ||
             Modifier.isAbstract(modifiers)) {
             throw new Exception("Invalid bean class modifier");
         }
         // Check that there is a 0 arg constructor
         bean.getConstructor(new Class[] {});
         generateNew = true;
     } catch (Exception e) {
         // Cannot instantiate the specified class
         if (ctxt.getOptions().getErrorOnUseBeanInvalidClassAttribute()) {
             err.jspError(n, "jsp.error.invalid.bean", klass);
         }
     }
}

At compile time - jasper is checking that the default constructor of a bean 
may be invoked. By invoking the constructor at compile time - the class is 
loaded by the JVM. This will in turn cause the JVM to call any static 
initializers. (In which you have)


-Tim


Marcus Beyer wrote:

> Tim Funk schrieb:
> 
>> There here, but your 1st post was a on a Friday afternoon. And the 
>> errors were not very clear. Stack traces and a better description is 
>> probably in order.
> 
> 
> I see :-)
> 
> === description ===
> 
> I am using the ant script I found on page
> <http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jasper-howto.html>. The 
> relevant software I use is Tomcat 5.0.26 (the one that comes with JBoss 
> 3.2.5) and JSF 1.1_01 reference implementation (the latest release).
> 
> BTW: Is there a way to let Tomcat do the job of JSP compilation on 
> deployment? I mean without the need of visiting each page manually?
> 
> === stack trace ===
> 
>   [jasper2] SCHWERWIEGEND: java.lang.NullPointerException
>   [jasper2] java.lang.RuntimeException: java.lang.NullPointerException
>   [jasper2] at MyHelper.getManagedBean(ManagedBeanHelper.java:43)
>   [jasper2] at MyBean.loadValues(DomainListBean.java:93)
>   [jasper2] at MyBean.<init>(DomainListBean.java:47)
>   [jasper2] at 
> sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>   [jasper2] at 
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
> 
>   [jasper2] at 
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
> 
>   [jasper2] at 
> java.lang.reflect.Constructor.newInstance(Constructor.java:274)
>   [jasper2] at java.lang.Class.newInstance0(Class.java:308)
>   [jasper2] at java.lang.Class.newInstance(Class.java:261)
>   [jasper2] at 
> org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1212) 
> 
>   [jasper2] at 
> org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
>   [jasper2] at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
>   [jasper2] at 
> org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
>   [jasper2] at 
> org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
>   [jasper2] at org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
>   [jasper2] at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
>   [jasper2] at 
> org.apache.jasper.compiler.Generator.generate(Generator.java:3261)
>   [jasper2] at 
> org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244)
>   [jasper2] at 
> org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
>   [jasper2] at org.apache.jasper.JspC.processFile(JspC.java:776)
>   [jasper2] at org.apache.jasper.JspC.execute(JspC.java:905)
>   [jasper2] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   [jasper2] at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
> 
>   [jasper2] at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
> 
>   [jasper2] at java.lang.reflect.Method.invoke(Method.java:324)
>   [jasper2] at 
> org.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:124)
>   [jasper2] at 
> org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:269)
>   [jasper2] at org.apache.tools.ant.Task.perform(Task.java:364)
>   [jasper2] at org.apache.tools.ant.Target.execute(Target.java:301)
>   [jasper2] at org.apache.tools.ant.Target.performTasks(Target.java:328)
>   [jasper2] at 
> org.apache.tools.ant.Project.executeTarget(Project.java:1215)
>   [jasper2] at 
> org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:379) 
> 
>   [jasper2] at 
> org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:135) 
> 
>   [jasper2] Caused by: java.lang.NullPointerException
>   [jasper2] at MyHelper.getManagedBean(ManagedBeanHelper.java:36)
>   [jasper2] ... 32 more
> 
> thanx!
> Marcus
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: precompilation trouble

Posted by Marcus Beyer <mb...@stormlight.de>.
Marcus Beyer schrieb:

> === description ===
> 
> I am using the ant script I found on page
> <http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jasper-howto.html>. 

Sorry, I mean this one:

<http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jasper-howto.html>

Marcus

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: precompilation trouble

Posted by Marcus Beyer <mb...@stormlight.de>.
Tim Funk schrieb:

> There here, but your 1st post was a on a Friday afternoon. And the 
> errors were not very clear. Stack traces and a better description is 
> probably in order.

I see :-)

=== description ===

I am using the ant script I found on page
<http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jasper-howto.html>. The 
relevant software I use is Tomcat 5.0.26 (the one that comes with JBoss 
3.2.5) and JSF 1.1_01 reference implementation (the latest release).

BTW: Is there a way to let Tomcat do the job of JSP compilation on 
deployment? I mean without the need of visiting each page manually?

=== stack trace ===

   [jasper2] SCHWERWIEGEND: java.lang.NullPointerException
   [jasper2] java.lang.RuntimeException: java.lang.NullPointerException
   [jasper2] at MyHelper.getManagedBean(ManagedBeanHelper.java:43)
   [jasper2] at MyBean.loadValues(DomainListBean.java:93)
   [jasper2] at MyBean.<init>(DomainListBean.java:47)
   [jasper2] at 
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   [jasper2] at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
   [jasper2] at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
   [jasper2] at 
java.lang.reflect.Constructor.newInstance(Constructor.java:274)
   [jasper2] at java.lang.Class.newInstance0(Class.java:308)
   [jasper2] at java.lang.Class.newInstance(Class.java:261)
   [jasper2] at 
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1212)
   [jasper2] at 
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
   [jasper2] at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
   [jasper2] at 
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
   [jasper2] at 
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
   [jasper2] at org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
   [jasper2] at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
   [jasper2] at 
org.apache.jasper.compiler.Generator.generate(Generator.java:3261)
   [jasper2] at 
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244)
   [jasper2] at 
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
   [jasper2] at org.apache.jasper.JspC.processFile(JspC.java:776)
   [jasper2] at org.apache.jasper.JspC.execute(JspC.java:905)
   [jasper2] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   [jasper2] at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   [jasper2] at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   [jasper2] at java.lang.reflect.Method.invoke(Method.java:324)
   [jasper2] at 
org.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:124)
   [jasper2] at 
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:269)
   [jasper2] at org.apache.tools.ant.Task.perform(Task.java:364)
   [jasper2] at org.apache.tools.ant.Target.execute(Target.java:301)
   [jasper2] at org.apache.tools.ant.Target.performTasks(Target.java:328)
   [jasper2] at 
org.apache.tools.ant.Project.executeTarget(Project.java:1215)
   [jasper2] at 
org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:379)
   [jasper2] at 
org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:135)
   [jasper2] Caused by: java.lang.NullPointerException
   [jasper2] at MyHelper.getManagedBean(ManagedBeanHelper.java:36)
   [jasper2] ... 32 more

thanx!
Marcus


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: precompilation trouble

Posted by Tim Funk <fu...@joedog.org>.
There here, but your 1st post was a on a Friday afternoon. And the errors 
were not very clear. Stack traces and a better description is probably in order.

-Tim

Marcus Beyer wrote:
> Marcus Beyer schrieb:
> 
>> Using Tomcat 5.0.26 I have some problems precompiling my pages with:
>>
>>       org.apache.jasper.JspC
>>
>> The precompiler instantiates some beans, altough I don't exactly know 
>> why. During instatiation some beans need to access managed beans, so 
>> they call something like this:
>>
>>       FacesContext facesContext = FacesContext.getCurrentInstance ( );
>>       /*
>>        * this happens if I try to precompile some jsp pages ...
>>        */
>>       if (facesContext == null) log.error ("no faces context found!");
> 
> 
> Hmm. Really no Tomcat experts here? Where can I find them?
> 
> Marcus
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: precompilation trouble

Posted by Marcus Beyer <mb...@stormlight.de>.
Marcus Beyer schrieb:

> Using Tomcat 5.0.26 I have some problems precompiling my pages with:
> 
>       org.apache.jasper.JspC
> 
> The precompiler instantiates some beans, altough I don't exactly know 
> why. During instatiation some beans need to access managed beans, so 
> they call something like this:
> 
>       FacesContext facesContext = FacesContext.getCurrentInstance ( );
>       /*
>        * this happens if I try to precompile some jsp pages ...
>        */
>       if (facesContext == null) log.error ("no faces context found!");

Hmm. Really no Tomcat experts here? Where can I find them?

Marcus


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org