【问题标题】:Error compiling JSPs in Apache Tomcat 8.0.12在 Apache Tomcat 8.0.12 中编译 JSP 时出错
【发布时间】:2014-11-12 04:08:27
【问题描述】:

我最近从 Apache Tomcat 6.X 升级到 7.X 到 8.0.12。我目前能够在 tomcat 8 中编译和运行我的应用程序;但是,我用于预编译 jsps 的 ant 任务不再有效。奇怪的是,如果我切换回 tomcat 7 而不进行任何其他更改,JspC 调用将起作用!

这是 ant 任务的错误输出:

2014 年 9 月 17 日下午 4:01:23 org.apache.jasper.servlet.TldScanner scanJars 信息:至少有一个 JAR 已扫描 TLD,但未包含 TLD。为此记录器启用调试日志记录,以获取已扫描但未在其中找到 TLD 的 JAR 的完整列表。在扫描期间跳过不需要的 JAR 可以缩短启动时间和 JSP 编译时间。 java.lang.NullPointerException 在 org.apache.jasper.compiler.TldCache.getTaglibXml(TldCache.java:97) 在 org.apache.jasper.compiler.TagLibraryInfoImpl.(TagLibraryInfoImpl.java:179) 在 org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:411) 在 org.apache.jasper.compiler.Parser.parseDirective(Parser.java:469) 在 org.apache.jasper.compiler.Parser.parseElements(Parser.java:1428) 在 org.apache.jasper.compiler.Parser.parse(Parser.java:139) 在 org.apache.jasper.compiler.ParserController.doParse(ParserController.java:227) 在 org.apache.jasper.compiler.ParserController.parse(ParserController.java:100) 在 org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199) 在 org.apache.jasper.compiler.Compiler.compile(Compiler.java:356) 在 org.apache.jasper.JspC.processFile(JspC.java:1217) 在 org.apache.jasper.JspC.execute(JspC.java:1368) 在 org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292) 在 sun.reflect.GeneratedMethodAccessor7.invoke(未知来源) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:483) 在 org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 在 org.apache.tools.ant.Task.perform(Task.java:348) 在 org.apache.tools.ant.Target.execute(Target.java:435) 在 org.apache.tools.ant.Target.performTasks(Target.java:456) 在 org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393) 在 org.apache.tools.ant.Project.executeTarget(Project.java:1364) 在 org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) 在 org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:36) 在 org.apache.tools.ant.Project.executeTargets(Project.java:1248) 在 org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:452) 在 org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:139)

这是蚂蚁任务:

<target name="jspc-tomcat" depends="compile" description="compile jsps using tomcat jspc">
    <copy overwrite="false" file="${webxml.dir}/web.xml" tofile="web/WEB-INF/web.xml" />

    <jasper
        uriroot="web"
        outputDir="${build.dir}/JSP/src" />

    <delete file="web/WEB-INF/web.xml"/>
</target>
<target name="compile-jsps" depends="jspc-tomcat" description="compile jsps using apache tomcat">
    <mkdir dir="${build.dir}/JSP/classes"/>
    <mkdir dir="${build.dir}/JSP/lib"/>
    <javac memoryInitialSize="128m" memoryMaximumSize="512m" destdir="${build.dir}/JSP/classes"
        optimize="off" fork="true"
        debug="on" failonerror="false" source="1.8" target="1.8"
        srcdir="${build.dir}/JSP/src" includeantruntime="false"
        excludes="**/*.smap">
        <classpath>
            <fileset dir="${local.ctx1.home}/lib">
                <include name="*.jar"/>
            </fileset>
            <fileset dir="${local.ctx1.home}/bin">
                <include name="*.jar"/>
            </fileset>
            <pathelement path="${rade2.class.dir}" />
            <path refid="compile_classpath" />
        </classpath>
        <include name="**" />
        <exclude name="tags/**" />
    </javac>
</target>

我尝试过使用标签库并确保它们都被正确声明。据我所知,他们是。我无法解释来自 TldCache.java 的 NullPointerException 的原因。有其他人经历过这种情况或对可能的解决方案有任何想法吗?

【问题讨论】:

  • 能否编辑${catalina.home}/conf/logging.properties下的文件设置org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = FINE,重启TOMCAT,然后贴出错误信息?这应该会告诉您哪个 JAR 缺少提到的那些 TLD。
  • 构建路径中包含很多不包含 TLD 的 JAR。我的理解是,我可以指定将它们排除在 TLD 搜索之外,以加快编译和 tomcat 启动时间,但允许搜索它们应该不是问题。您确实提出了一个很好的观点:我可以尝试排除所有这些 JAR 以查看是否可以防止错误。我今天必须试试。我仍然相信它应该能够编译 JSP,无论在构建路径中包含没有 TLD 的 JAR。我的假设是正确的还是我误解了?
  • 我能够通过在 tomcat 服务器 context.xml 中添加 JarScanner 和 defaultTldScan="false" 来消除服务器启动时的 TLD 错误,但这不会影响我的编译错误或 TLD INFO 消息在 JSP 编译期间发布。我还尝试将设置 tomcat.util.scan.StandardJarScanFilter.jarsToSkip 添加到 logging.properties 文件中,但它似乎对服务器启动或 ant 任务编译没有任何影响。

标签: jsp tomcat ant compiler-errors tomcat8


【解决方案1】:

我发现我的 WEB-INF/tags 目录中定义了一个 .tld 文件,该文件被明确排除在 ant 目标中。从 ant 目标中删除排除项不起作用,因此我将 .tld 定义移动到 /WEB-INF/jsps。我还必须恢复我对 jasper taskdef 的定义,我已将其更改为从 catalina-ant.xml per Apache's documentation 导入。

总之,将 .tld 从 WEB-INF/tags 移动到 WEB-INF/jsps 并在 ant 中添加了一个 jasper taskdef。

最终的ant任务如下:

<target name="jspc-tomcat" depends="compile"
 description="compile jsps using tomcat jspc">
    <copy overwrite="false" file="${webxml.dir}/web.xml"
        tofile="web/WEB-INF/web.xml" />
    <taskdef classname="org.apache.jasper.JspC" name="jasper">
        <classpath id="jspc.classpath">
            <pathelement location="${java.home}/../lib/tools.jar"/>
            <fileset dir="${local.ctx1.home}/bin">
                <include name="*.jar"/>
            </fileset>
            <fileset dir="${local.ctx1.home}/lib">
                <include name="*.jar"/>
            </fileset>
            <pathelement path="${rade2.class.dir}" />
            <path refid="compile_classpath" />
        </classpath>
    </taskdef>

    <jasper
        uriroot="web"
        outputDir="${build.dir}/JSP/src" />

    <delete file="web/WEB-INF/web.xml"/>
</target>
<target name="compile-jsps" depends="jspc-tomcat" description="compile jsps using apache tomcat">
    <mkdir dir="${build.dir}/JSP/classes"/>
    <mkdir dir="${build.dir}/JSP/lib"/>
    <javac memoryInitialSize="128m" memoryMaximumSize="512m" destdir="${build.dir}/JSP/classes"
        optimize="off" fork="true"
        debug="on" failonerror="false" source="1.8" target="1.8"
        srcdir="${build.dir}/JSP/src" includeantruntime="false"
        excludes="**/*.smap">
        <classpath>
            <fileset dir="${local.ctx1.home}/lib">
                <include name="*.jar"/>
            </fileset>
            <fileset dir="${local.ctx1.home}/bin">
                <include name="*.jar"/>
            </fileset>
            <pathelement path="${rade2.class.dir}" />
            <path refid="compile_classpath" />
        </classpath>
        <include name="**" />
        <exclude name="tags/**" />
    </javac>
</target>

【讨论】:

  • 我所做的只是将我的 .tld 文件移出 tags 目录,然后一切都恢复正常了。
猜你喜欢
  • 1970-01-01
  • 2014-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-12
  • 2012-10-22
  • 1970-01-01
相关资源
最近更新 更多