开发者

How can I use use JSP 2.1 with Cargo maven plugin and Jetty6x embedded?

开发者 https://www.devze.com 2023-01-04 19:01 出处:网络
I have a webapp that is using JSP 2.1, Servlets 2.5 and JSTL 1.2 on Java 6. I do my testing using the maven-jetty-plugin 6.1.1rc1 without any problems. From this link: http://docs.codehaus.org/display

I have a webapp that is using JSP 2.1, Servlets 2.5 and JSTL 1.2 on Java 6. I do my testing using the maven-jetty-plugin 6.1.1rc1 without any problems. From this link: http://docs.codehaus.org/display/JETTY/JSP+2.0+v+JSP+2.1, I understand that jetty 6 will select JSP 2.1 if on JDK 5+, which is working fine.

Here is the relevant section from my pom.xml of the application war:

<!--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> 

Now I'd like to set up automated integration tests using cargo and jetty6x embedded. The container starts up fine without errors. However, I can't render any JSPs. This is the exception I get, which as far as I can tell is because a JSP-2.0 impl is being used instead of JSP-2.1.

(TagLibraryInfoImpl.java:547) - Unknown element (deferred-value) in attribute

and 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)

Here is my cargo config:

<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0.1</version>
<configuration>
    <container>
        <containerId&g开发者_运维百科t;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>

The cargo jetty6x container also uses v6.1.1rc1 of jetty, so it must be something to do with the way cargo is using jetty. I know that cargo hard-codes the versions of its container dependencies instead of using the maven dependency mechanism (probably for good reason, jira ->CARGO-571)

So my question is: has anybody else managed to use JSP 2.1 with cargo and jetty 6x embedded? Any suggestions for getting it working?

Any help much appreciated!


OK, managed to figure this one out. This post from the cargo mailing list was helpful: http://old.nabble.com/Jetty6-version-with-maven-plugin-td16722550.html. It described how you can customize the classpath of the container using cargo, but if you take this approach then you need to specify all the dependencies manually.

I found from the cargo sources that these are the dependencies used by default for jetty6x containers:

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"));

The problematic ones are the tomcat ones, because they use JSP 2.0. So when setting up the classpath, you need to exclude those, and include JSP-2.1, i.e.

<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>

So here is the whole configuration:

<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>

Note that you need to specify all of the dependencies twice - once in the plugin and once as project dependencies. You can get the versions from the first snippet.

0

精彩评论

暂无评论...
验证码 换一张
取 消