3

I am interested in pre-compiling all my JSPs in Tomcat 7 for debugging purposes and getting a log of all JSP compilation errors. I have searched all over the net and have not found any way to do this.

Does anybody have suggestions on how to do this with out of the box Open Source tools?

Timothy C. Quinn
  • 3,739
  • 1
  • 35
  • 47
  • If you are using an IDE like eclipse, it should mark any compilation errors during editing it – fujy Sep 06 '13 at 23:02
  • And if what you need is to debug JSPs in runtime, this is a possible duplicates http://stackoverflow.com/questions/123462/debug-jsp-from-eclipse and http://programmers.stackexchange.com/questions/40564/how-can-i-debug-a-jsp – fujy Sep 06 '13 at 23:07
  • @fujy, thanks for the comment. My preference not to depend on an IDE but that approach should work. I spent some time trying to use jspc through ant script but that have had no luck with that approach. Fortunately, the use case for this bulk compile is not a common one so setup time is not a big factor. – Timothy C. Quinn Sep 07 '13 at 03:02

1 Answers1

1

I was able to get this task complete using the ANT build approach as documented here on Dev Shed and referenced here on Stack Overflow.

What was required to get this working was adding failonerror="false" to the javac task as shown here:

<!-- start snip from build.xml from DevShed -->
<target name="generate-jsp-java-src"> 
    <mkdir dir="${webapp.dir}/WEB-INF/jspc-src/${jspc.dir.prefix}"/>
    <taskdef classname="org.apache.jasper.JspC" name="jasper2">
        <classpath>
            <path refid="jspc.classpath"/>
        </classpath>
    </taskdef>
    <touch file="${webapp.dir}/WEB-INF/jspc-web.xml"/>
    <jasper2 uriroot="${webapp.dir}"
        package="${jspc.pkg.prefix}" 
        webXmlFragment="${webapp.dir}/WEB-INF/jspc-web.xml" 
        outputDir="${webapp.dir}/WEB-INF/jspc-src/${jspc.dir.prefix}"
        verbose="0"
        failonerror="false"
        listerrors="true"/>
</target> 
<!-- end snip from build.xml from DevShed -->

I also found that setting verbose="0" and listerrors="true" does a better job in showing just the compilation / build errors and getting less un-needed logging.

Additional handy note that I learned from this exercise is that ANT will automatically try to reflect setter methods based on the javac attributes in your task. If Ant finds matching the signature, it will execute this setter method. For example failonerror will reflect to setFailOnError(boolean) by ANT. Thus, if you want to see what other parameters are available, you can simply open JspC.java and see what public setters are available and give them a go by removing "get" and putting as lower case (for consistency sake).

I suspect that this ANT setter reflection is consistent across other Java based tasks.

Community
  • 1
  • 1
Timothy C. Quinn
  • 3,739
  • 1
  • 35
  • 47