我有一个在Java 6上使用JSP 2.1,Servlets 2.5和JSTL 1.2的webapp。我使用maven-jetty-plugin 6.1.1rc1进行测试没有任何问题。从这个链接:http://docs.codehaus.org/display/JETTY/JSP+2.0+v+JSP+2.1,我知道如果在JDK 5+上,jetty 6将选择JSP 2.1,这是正常的。
以下是应用程序之战的pom.xml中的相关部分:
<!--servlet & javax-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
现在我想使用cargo和jetty6x嵌入式设置自动集成测试。容器启动正常,没有错误。但是,我无法呈现任何JSP。这是我得到的例外,据我所知,因为正在使用JSP-2.0 impl而不是JSP-2.1。
(TagLibraryInfoImpl.java:547) - Unknown element (deferred-value) in attribute
和Caused by: java.lang.NoSuchMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;
at org.apache.taglibs.standard.tag.common.core.SetSupport.doEndTag(SetSupport.java:140)
这是我的货物配置:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0.1</version>
<configuration>
<container>
<containerId>jetty6x</containerId>
<type>embedded</type>
</container>
<configuration>
<deployables>
<deployable>
<groupId>groupId</groupId>
<artifactId>artifact</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
<wait>${cargo.wait}</wait>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
货物jetty6x集装箱也使用v6.1.1rc1码头,所以它必须与货物使用码头的方式有关。我知道货物硬编码其容器依赖的版本而不是使用maven依赖机制(可能有充分的理由,jira - &gt;&gt; CARGO-571)
所以我的问题是:有没有其他人设法使用带有货物和码头6x嵌入式的JSP 2.1?任何让它运作的建议?
非常感谢任何帮助!
答案 0 :(得分:1)
好的,设法解决这个问题。来自货物邮件列表的这篇文章很有帮助: http://old.nabble.com/Jetty6-version-with-maven-plugin-td16722550.html。它描述了如何使用cargo自定义容器的类路径,但如果采用这种方法,则需要手动指定所有依赖项。
我从货源中发现这些是jetty6x容器默认使用的依赖项:
jetty6xDependencies.add(new Dependency("org.mortbay.jetty", "jsp-api-2.0", "6.1.1rc1"));
jetty6xDependencies.add(new Dependency("org.mortbay.jetty", "servlet-api-2.5", "6.1.1rc1"));
jetty6xDependencies.add(new Dependency("org.mortbay.jetty", "jetty", "6.1.1rc1"));
jetty6xDependencies.add(new Dependency("org.mortbay.jetty", "jetty-util", "6.1.1rc1"));
jetty6xDependencies.add(new Dependency("org.mortbay.jetty", "jetty-naming", "6.1.1rc1"));
jetty6xDependencies.add(new Dependency("org.mortbay.jetty", "jetty-plus", "6.1.1rc1"));
jetty6xDependencies.add(new Dependency("ant", "ant", "1.6.5"));
jetty6xDependencies.add(new Dependency("commons-el", "commons-el", "1.0"));
jetty6xDependencies.add(new Dependency("tomcat", "jasper-compiler", "5.5.15"));
jetty6xDependencies.add(new Dependency("tomcat", "jasper-runtime", "5.5.15"));
jetty6xDependencies.add(new Dependency("tomcat", "jasper-compiler-jdt","5.5.15"));
jetty6xDependencies.add(new Dependency("javax.mail", "mail", "1.4"));
jetty6xDependencies.add(new Dependency("javax.activation", "activation", "1.1"));
jetty6xDependencies.add(new Dependency("geronimo-spec", "geronimo-spec-jta", "1.0.1B-rc4"));
jetty6xDependencies.add(new Dependency("xerces", "xercesImpl","2.6.2"));
jetty6xDependencies.add(new Dependency("xerces", "xmlParserAPIs","2.6.2"));
jetty6xDependencies.add(new Dependency("commons-logging", "commons-logging","1.0.4"));
jetty6xDependencies.add(new Dependency("log4j", "log4j", "1.2.14"));
有问题的是tomcat,因为它们使用JSP 2.0。因此,在设置类路径时,您需要排除这些,并包含JSP-2.1,即
<dependencies>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1</artifactId>
<version>6.1.1rc1</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>core</artifactId>
<version>3.1.1</version>
</dependency>
所以这是整个配置:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0.1</version>
<configuration>
<container>
<containerId>jjetty6x</containerId>
<type>embedded</type>
<implementation>
org.codehaus.cargo.container.jetty.Jetty6xEmbeddedLocalContainer
</implementation>
<timeout>500000</timeout>
<dependencies>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-api-2.1</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xmlParserAPIs</artifactId>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</dependency>
<dependency>
<groupId>geronimo-spec</groupId>
<artifactId>geronimo-spec-jta</artifactId>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</dependency>
<!--replaced these:-->
<!--<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-compiler</artifactId>
</dependency>
<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-runtime</artifactId>
</dependency>
<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-compiler-jdt</artifactId>
</dependency>-->
<!--with this:-->
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>core</artifactId>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api-2.5</artifactId>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-util</artifactId>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-naming</artifactId>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-plus</artifactId>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</dependency>
<dependency>
<groupId>commons-el</groupId>
<artifactId>commons-el</artifactId>
</dependency>
</dependencies>
</container>
<configuration>
<deployables>
<deployable>
<groupId>gruopId</groupId>
<artifactId>artifact</artifactId>
<type>war</type>
</deployable>
</deployables>
<implementation>
org.codehaus.cargo.container.jetty.Jetty6xEmbeddedStandaloneLocalConfiguration
</implementation>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
请注意,您需要两次指定所有依赖项 - 一次在插件中,一次作为项目依赖项。您可以从第一个代码段中获取版本。