tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Coetmeur, Alain" <alain.coetm...@caissedesdepots.fr>
Subject RE: [Solution] Debugging JSP with jasper(tomcat4) : java compile with -g flag
Date Thu, 11 Oct 2001 09:06:13 GMT
since nobody seems to have a solution, I publish
the one I found. 
IMHO it should be integrated into standard tomcat,
until a better way is found...

could someobe forward my proposition 

I've created a SunJavaCompilerClassDebug derived
from SunJavaCompilerClass, that just call
javac with a "-g" option...

than in the "web.xml" of my web app
I've added:
  <!-- The java debug JSP servlet 
     nb: put a break on org.apache.jasper.runtime.HttpJspBase.service, then
step to the jsp -->
  <servlet>
    <servlet-name>jspDebug</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    <init-param>
      <param-name>jspCompilerPlugin</param-name>
 
<param-value>org.apache.jasper.compiler.SunJavaCompilerDebug</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

and
  <servlet-mapping>
    <servlet-name>jspDebug</servlet-name>
    <url-pattern>*.jsp</url-pattern>
  </servlet-mapping>

note that the global web.xml in conf/ already define
the "jsp" servlet mapped to *.jsp
If I try to overide the "jsp" servlet name,  tomcat refuses.
however overiding the *.jsp servlet mapping does work.

to debug with sources I have to
- copy the *$jsp.java in work/localhost/webapp-name/
  into a sourcepathdir/org/apache/jsp/ directory (because it is defined this
package)
  NB: one good idea in tomcat4
   would be to move the generated classes
   to a work/localhost/webapp-name/org/apache/jsp/ 
- add the given sourcepathdir to "jdb" sourcepath

note that I still have a problem.
If I put a breakpoint on the jsp service method 
org.apache.jsp.mypage$jsp._jspService
it works the first time,
but If I redeploy it (I'm under jboss and this may 
make the things more triccky about classloaders)
my breakpoint doesn't work, and I cannot even
put a breakpoint anywhere in the generated jsp class ...

the only way is to put a break on 
org.apache.jasper.runtime.HttpJspBase.service
and step into my newly deployed jsp class

by the way is there a good Java JPDA source debugger GUI 
like xxgdb on X11/Unix...

> -----Message d'origine-----
> De: Coetmeur, Alain [mailto:alain.coetmeur@caissedesdepots.fr]
> Date: mercredi 10 octobre 2001 09:59

> I'm developing JSP's (and EJB, and servlets)
> on the  embedded Catalina/Jasper engine of Jboss...
> (I'm using the jboss EAR or WAR deployer, with ant.. cool)
> 
> all work fine, and to debug
> I can plug jdb on the server JVM
> and compile my java code with the debug flag on.
> 
> however to debug the servlets generated
> from the JSP by the jasper engine, I need
> to set the debug flag on...
> 
> where can I control the debug flag of 
> jasper generated servlets ?
> 

-------------
/* standard headers
   ...... 
*/
package org.apache.jasper.compiler;

import java.io.OutputStream;
import sun.tools.javac.Main;

/**
 * a derivation of   SunJavaCompiler that sets the "generate debug
information" (-g) option 
 *
 * At some point we need to make sure there is a class like this for
 * JDK 1.3, and other javac-like animals that people want to use. 
 *
 * @author Anil K. Vijendran, then derived by
Alain.Coetmeur@caissedesdepots.fr to compile with debug
 */
public class SunJavaCompilerDebug extends SunJavaCompiler implements
JavaCompiler  {

    /**
      * same code as SunJavaCompiler, except the new "-g" option
     */	
    public boolean compile(String source) {
        Main compiler = new Main(out, "jsp->javac");
	String[] args = null;

	if( outdir != null ) {
            args = new String[]
            {
                "-g", /* AC: that is the point ! */
                "-encoding", encoding,
                "-classpath", classpath,
                "-d", outdir,
                source
            };
	} else {
            args = new String[]
            {
                "-g", /* AC: that is the point ! */
                "-encoding", encoding,
                "-classpath", classpath,
                source       
            };
	}
	//System.out.println("SunJavaCompilerDebug compile("+args+")");
        return compiler.compile(args);
    }
}

Mime
View raw message