我正在使用Maven Cargo插件启动Jetty Web容器,以便在单独的项目模块中运行某些集成测试。
当我将taglibs添加到jsp页面并尝试从集成测试中击中它们时,我正在努力解决这个问题。当jetty尝试编译页面时,它失败并出现此错误:
org.apache.jasper.JasperException: Unable to initialize TldLocationsCache: null
当在已安装的Tomcat容器中运行时,Web应用程序运行正常,或者在命令行上通过maven运行独立Jetty,所以我认为问题必须归结为货物嵌入码头的方式以及jetty如何编译应用程序。
我尝试在forked和unforked模式下运行,将taglibs添加到容器类路径中,在web.xml中显式定义taglibs并且没有配置......都无济于事。
这是我用来调试的测试项目:
的web.xml
<?xml version='1.0' encoding='UTF-8'?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>taglibs-test</display-name>
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tld/c.tld</taglib-location>
</taglib>
</jsp-config>
测试模块pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/maven-v4_0_0.xsd“&GT;
...
<build>
<!-- Integration Test Embedded Servlet Container -->
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<wait>false</wait>
<container>
<containerId>jetty6x</containerId>
<type>embedded</type>
<log>${project.build.directory}/log</log>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
</dependency>
</dependencies>
<systemProperties>
<DEBUG>true</DEBUG>
</systemProperties>
</container>
<configuration>
<properties>
<cargo.servlet.port>8090</cargo.servlet.port>
<cargo.logging>high</cargo.logging>
</properties>
<deployables>
<deployable>
<groupId>test</groupId>
<artifactId>web</artifactId>
<type>war</type>
<properties>
<context>taglibs-test</context>
</properties>
</deployable>
</deployables>
</configuration>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>test-compile</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>package</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
这是错误的堆栈跟踪:
2009-01-24 13:53:06.766::WARN: /taglibs-test/index.jsp:
org.apache.jasper.JasperException: Unable to initialize TldLocationsCache: null
at org.apache.jasper.compiler.TldLocationsCache.init(TldLocationsCache.java:253)
at org.apache.jasper.compiler.TldLocationsCache.getLocation(TldLocationsCache.java:224)
at org.apache.jasper.JspCompilationContext.getTldLocation(JspCompilationContext.java:526)
at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:422)
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:492)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1552)
at org.apache.jasper.compiler.Parser.parse(Parser.java:126)
at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:211)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:155)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
我在jasper的TldLocationsCache中跟踪了以下几行:
private void init() throws JasperException {
if (initialized) return;
try {
processWebDotXml();
scanJars();
processTldsInFileSystem("/WEB-INF/");
initialized = true;
} catch (Exception ex) {
throw new JasperException(Localizer.getMessage(
"jsp.error.internal.tldinit", ex.getMessage()));
}
}
非常感谢任何帮助!!
凸轮