在Maven项目中以嵌入模式配置Jetty JSP支持

时间:2010-11-20 21:25:15

标签: jsp jetty embedded-jetty

我可以使用Jetty访问.html页面,但是当我访问.jsp页面时,我得到:

  

0 13:21:13 / [INFO]没有JSP支持。   检查JSP jar是否在lib / jsp和   已指定JSP选项   start.jar

我将以下内容添加为依赖项:

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

这是否符合“检查JSP jar是否在lib / jsp中”部分错误消息?

另外,我不知道“检查是否已经为start.jar指定了JSP选项”是指在此上下文中。我有以下内容:

  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();
  }

6 个答案:

答案 0 :(得分:17)

我通过添加Mortbay JSP依赖项来实现它(这是Gradle表示法,但你明白了):

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'

larger writeup available on my blog

答案 1 :(得分:10)

我知道这已经回答了一段时间。我无法得到Ben McCann为我工作的答案。但是,通过添加

直接向Jetty添加JSP支持,我很幸运
    <!--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>

奇怪的是,我原来的版本6.1.24不支持。

总而言之,这使得我的pom.xml看起来像这样:

  

  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>
     

和我的开始课程(我在文件夹\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 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();
            }
        }
    }
}
     

}

答案 2 :(得分:10)

我没有使用Jetty发行版中的jar,只使用Maven依赖项:

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

答案 3 :(得分:6)

以Simon Huet的优秀答案为基础,这是我的看法:

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

答案 4 :(得分:1)

在阅读了这个stackoverflow页面(好工作)以及http://wiki.eclipse.org/Jetty/Howto/Configure_JSP后,我终于得到了这个工作。由于我的配置略有不同,我以为我会回馈。我有一个没有'javac'编译器的嵌入式Jetty 8安装,我通过使用eclipse编译器并在创建服务器之前设置系统属性来实现它,如下所示:

System.setProperty("org.apache.jasper.compiler.disablejsr199", "true");
Server server = new Server();

使用以下maven配置:

<dependency>
  <groupId>org.apache.geronimo.specs</groupId>
  <artifactId>geronimo-servlet_3.0_spec</artifactId>
  <version>1.0</version>
</dependency>
<dependency>
  <groupId>org.eclipse.jetty.orbit</groupId>
  <artifactId>javax.el</artifactId>
  <version>2.2.0.v201108011116</version>
</dependency>
<dependency>
  <groupId>org.eclipse.jetty.orbit</groupId>
  <artifactId>javax.servlet.jsp</artifactId>
  <version>2.2.0.v201112011158</version>
</dependency>
<dependency>
  <groupId>org.eclipse.jetty.orbit</groupId>
  <artifactId>javax.servlet.jsp.jstl</artifactId>
  <version>1.2.0.v201105211821</version>
</dependency>
<dependency>
  <groupId>org.eclipse.jetty.orbit</groupId>
  <artifactId>org.apache.jasper.glassfish</artifactId>
  <version>2.2.2.v201112011158</version>
</dependency>
<dependency>
  <groupId>org.eclipse.jetty.orbit</groupId>
  <artifactId>org.apache.taglibs.standard.glassfish</artifactId>
  <version>1.2.0.v201112081803</version>
</dependency>
<dependency>
  <groupId>org.eclipse.jetty.orbit</groupId>
  <artifactId>org.eclipse.jdt.core</artifactId>
  <version>3.7.1</version>
</dependency>

答案 5 :(得分:1)

Jetty 9.1.3,http://www.eclipse.org/jetty/documentation/current/configuring-jsp.html,只是添加jetty-jsp为我工作(加上来自url的web.xml配置)。无需从码头groupId外部添加罐子(即mortbay)。