Configuring Jetty JSP support in embedded mode in Maven project

36,093

Solution 1

I got it to work by adding the Mortbay JSP dependency (this is in Gradle notation, but you get the idea):

compile 'org.eclipse.jetty:jetty-io:8.0.0.M3'
compile 'org.eclipse.jetty:jetty-server:8.0.0.M3'
compile 'org.eclipse.jetty:jetty-servlet:8.0.0.M3'
compile 'org.eclipse.jetty:jetty-util:8.0.0.M3'
compile 'org.eclipse.jetty:jetty-webapp:8.0.0.M3'
compile 'org.mortbay.jetty:jsp-2.1-glassfish:2.1.v20100127'

There's a larger writeup available on my blog.

Solution 2

I know this has been answered a while ago. I could not get the answer from Ben McCann to work for me. However, i had luck by adding JSP support directly to Jetty by adding

    <!--jsp support for jetty, add the 2 following -->
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jsp-2.1</artifactId>
        <version>6.1.14</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jsp-api-2.1</artifactId>
        <version>6.1.14</version>
        <type>jar</type>
    </dependency>

Strangely, this was not supported by the version 6.1.24 I originally had.

So in total, that made my pom.xml look like this:

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>wikiproject</groupId>
<artifactId>wikiproject</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <jetty.version>6.1.14</jetty.version>
</properties>


<!-- Jetty dependencies -->
<dependencies>
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty</artifactId>
        <version>${jetty.version}</version>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-util</artifactId>
        <version>${jetty.version}</version>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-plus</artifactId>
        <version>${jetty.version}</version>
        <type>jar</type>
    </dependency>

    <!--jsp support for jetty, add the 2 following -->
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jsp-2.1</artifactId>
        <version>${jetty.version}</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jsp-api-2.1</artifactId>
        <version>${jetty.version}</version>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>org.apache.ant</groupId>
        <artifactId>ant-antlr</artifactId>
        <version>1.7.1</version>
    </dependency>

</dependencies>

and my start class (which i added in folder \src\test\java\com\company\wikiproject )

package com.company.wikiproject;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.webapp.WebAppContext;
/**  
 * User: Jesper Rønn-Jensen  
 * start wiki pages  
 */

public class Start {

public static void main(String[] args) {
    Server jettyServer = null;
    try {
        jettyServer = new Server();

        SocketConnector conn = new SocketConnector();
        conn.setPort(8080);
        jettyServer.setConnectors(new Connector[]{conn});

        WebAppContext context = new WebAppContext();
        context.setContextPath("/");
        context.setWar("src/main/webapp");

        jettyServer.setHandler(context);
        jettyServer.start();
    } catch (Exception ignore) {
        if (jettyServer != null) {
            try {
                jettyServer.stop();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }
}

}

Solution 3

I have done it without using the jars from the Jetty distribution, using only Maven dependencies:

<properties>
    <jetty.version>8.1.0.RC0</jetty.version>
    <glassfish.javax.version>2.2.3</glassfish.javax.version>
    <glassfish.javax-impl.version>2.2</glassfish.javax-impl.version>
    <glassfish.jstl.version>1.2</glassfish.jstl.version>
</properties>

<dependencies>
    <!-- Jetty Webapp-->
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-webapp</artifactId>
        <version>${jetty.version}</version>
    </dependency>

    <!-- JSP Support -->
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>javax.servlet.jsp</artifactId>
        <version>${glassfish.javax.version}</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jsp-impl</artifactId>
        <version>${glassfish.javax-impl.version}</version>
    </dependency>

    <!-- EL Support -->
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>javax.el</artifactId>
        <version>${glassfish.javax.version}</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>el-impl</artifactId>
        <version>${glassfish.javax-impl.version}</version>
    </dependency>

    <!-- JSTL Support -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>${glassfish.jstl.version}</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jstl-impl</artifactId>
        <version>${glassfish.jstl.version}</version>
    </dependency>
</dependencies>

Solution 4

Building upon Simon Huet's excellent answer, here's my take:

<properties>
    <bundle.name>nsb-${project.version}</bundle.name>
    <glassfish.javax.version>2.2.3</glassfish.javax.version>
    <glassfish.javax-jstl.version>1.2.1</glassfish.javax-jstl.version>
</properties>

<dependencies>

    <!-- Jetty Webapp -->
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-webapp</artifactId>
        <version>${jetty.version}</version>
    </dependency>

    <!-- JSP Support -->
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>javax.servlet.jsp</artifactId>
        <version>${glassfish.javax.version}</version>
    </dependency>

    <!-- EL Support -->
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>javax.el</artifactId>
        <version>${glassfish.javax.version}</version>
    </dependency>

    <!-- JSTL Support -->
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>javax.servlet.jsp.jstl</artifactId>
        <version>${glassfish.javax-jstl.version}</version>
        <exclusions>
            <exclusion>
                <artifactId>jstl-api</artifactId>
                <groupId>javax.servlet.jsp.jstl</groupId>
            </exclusion>
        </exclusions>
    </dependency>

</dependencies>

Solution 5

Jetty 9.1.3, http://www.eclipse.org/jetty/documentation/current/configuring-jsp.html, and just adding jetty-jsp worked for me (plus the web.xml config from the url). No need to add jars from outside the jetty groupId (ie. mortbay).

Share:
36,093
Ben McCann
Author by

Ben McCann

Updated on July 09, 2022

Comments

  • Ben McCann
    Ben McCann almost 2 years

    I can visit .html pages with Jetty, but when I visit a .jsp page I get:

    0 13:21:13 / [INFO] No JSP support. Check that JSP jars are in lib/jsp and that the JSP option has been specified to start.jar

    I added the following as dependencies:

    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-webapp</artifactId>
      <version>8.0.0.M1</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
    </dependency>
    

    Does that fulfill the "check that JSP jars are in lib/jsp" part of the error message?

    Also, I have no idea what "check that the JSP option has been specified to start.jar" means in this context. I have the following:

      public static void main(String[] args) throws Exception {
        Server server = new Server();
    
        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setPort(8080);
        server.addConnector(connector);
    
        WebAppContext webApp = new WebAppContext();
        webApp.setContextPath("/");
        webApp.setWar("src/main/webapp");
        server.setHandler(webApp);
        server.start();
        server.join();
      }
    
  • Ben McCann
    Ben McCann about 13 years
    This only works for Jetty 6 and older. That's pretty old since Jetty 8 is almost out now. I updated my answer to provide a better solution, so take another look.
  • Travis Schneeberger
    Travis Schneeberger over 12 years
    Jetty 8 supports the jsp 2.2. In the jetty hightide 8.0.0 distro they include the following in the jsp dir: com.sun.el_2.2.0.v201105051105.jar javax.el_2.2.0.v201105051105.jar javax.servlet.jsp.jstl_1.2.0.v201004190952.jar javax.servlet.jsp_2.2.0.v201103241009.jar org.apache.jasper.glassfish_2.2.2.v201108011116.jar org.apache.taglibs.standard.glassfish_1.2.0.v201004190952.ja‌​r I'm assuming this will give you jsp 2.2 support. The downside is this a lot of jars to keep track of. I wonder when jetty will have a jetty-jsp.jar? It would sure be nice!
  • Travis Schneeberger
    Travis Schneeberger over 12 years
    Actually, the jetty distribution has these dependencies as well. They can be found at the following url: [download.eclipse.org/jetty/orbit] The jetty distribution's pom downloads the jars at that url and packs them in the distribution's lib directory.
  • Asaf Mesika
    Asaf Mesika about 12 years
    Wow, I tried all solutions below which caused a lot of missing classes: ExpressionFactory and more. This was the only one that simply worked
  • Maddin
    Maddin almost 12 years
    This is still a valuable answer, since e.g. Solr ships with jetty 6. You can just add org.mortbay.jetty:jsp-2.1:6.1.14 to your POM and combine it with any jetty 6 version. The Maven central doesn't have version 6.1.26 of jsp-2.1.