jsp - 在 Apache Tomcat 8.0.12 中编译 JSP 时出错

标签 jsp tomcat ant compiler-errors tomcat8

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

这是 ant 任务的错误输出:

Sep 17, 2014 4:01:23 PM org.apache.jasper.servlet.TldScanner scanJars
    INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
    java.lang.NullPointerException
        at org.apache.jasper.compiler.TldCache.getTaglibXml(TldCache.java:97)
        at org.apache.jasper.compiler.TagLibraryInfoImpl.(TagLibraryInfoImpl.java:179)
        at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:411)
        at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:469)
        at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1428)
        at org.apache.jasper.compiler.Parser.parse(Parser.java:139)
        at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:227)
        at org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
        at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
        at org.apache.jasper.JspC.processFile(JspC.java:1217)
        at org.apache.jasper.JspC.execute(JspC.java:1368)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:435)
        at org.apache.tools.ant.Target.performTasks(Target.java:456)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:36)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
        at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:452)
        at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:139)

Here is the ant task:

<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 的原因。有没有其他人遇到过这种情况或对可能的解决方案有任何想法?

最佳答案

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

总而言之,将 .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>

关于jsp - 在 Apache Tomcat 8.0.12 中编译 JSP 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25902137/

相关文章:

java - 为什么运行jsp文件时我的所有bean属性都为空

html - 我的 jsp 没有看到 css

oracle - 配置数据库连接池 - Axis2 webservice

java - 启动 Apache tomcat 服务器时出错

java - 制作带有源代码和项目结构的 .jar 文件?

jsp - JSP/Servlet 的隐藏特性

java - 在两个不同的 html 表中显示从 GAE 数据存储中检索到的数据

jakarta-ee - Red 5 录制 RTMP 网络摄像头配置适用于本地主机,但不适用于外部服务器

java - 导出到 JAR,不包括一些附加文件

java - 使用 Ivy/ant 从命令行将符号名称解析为版本号?