【问题标题】:Configuring Jetty JSP support in embedded mode in Maven project在 Maven 项目中以嵌入模式配置 Jetty JSP 支持
【发布时间】:2010-11-20 21:25:15
【问题描述】:

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

0 13:21:13 / [INFO] 不支持 JSP。 检查 JSP jar 是否在 lib/jsp 中,并且 已指定 JSP 选项 开始.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 中”部分?

另外,我不知道“检查 JSP 选项是否已指定为 start.jar”在这种情况下是什么意思。我有以下内容:

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

【问题讨论】:

    标签: jsp jetty embedded-jetty


    【解决方案1】:

    我通过添加 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

    【讨论】:

    • Jetty 8 支持 jsp 2.2。在 jetty hightide 8.0.0 发行版中,它们在 jsp 目录中包含以下内容:com.sun.el_2.2.0.v201105051105.jarjavax.el_2.2.0.v201105051105.jarjavax.servlet.jsp.jstl_1.2.0.v201004190952.jarjavax.servlet.jsp_2.2.0.v201103241009.jarorg.apache.jasper.glassfish_2.2.2.v201108011116.jarorg.apache.taglibs.standard.glassfish_1.2.0.v201004190952.jar 我假设这将为您提供 jsp 2.2 支持。缺点是需要跟踪很多罐子。我想知道jetty什么时候会有jetty-jsp.jar?一定会很好!
    • 其实jetty发行版也有这些依赖。它们可以在以下 url 找到:[download.eclipse.org/jetty/orbit]jetty 发行版的 pom 下载该 url 处的 jar 并将它们打包到发行版的 lib 目录中。
    • 哇,我尝试了以下所有导致大量缺失类的解决方案:ExpressionFactory 等等。这是唯一一个简单的工作
    【解决方案2】:

    我没有使用 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】:

      我知道这个问题已经得到了回答。我无法从 Ben McCann 那里得到为我工作的答案。但是,我很幸运,通过添加将 JSP 支持直接添加到 Jetty

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

      }

      【讨论】:

      • 这仅适用于 Jetty 6 及更早版本。这已经很老了,因为 Jetty 8 现在快要出来了。我更新了我的答案以提供更好的解决方案,所以再看看。
      • 这仍然是一个有价值的答案,因为例如Solr 附带 jetty 6。您只需将 org.mortbay.jetty:jsp-2.1:6.1.14 添加到您的 POM 并将其与任何 jetty 6 版本结合使用。 Maven 中心没有 jsp-2.1 的 6.1.26 版本。
      【解决方案4】:

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

      【讨论】:

        【解决方案5】:

        在阅读了这个 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>
        

        【讨论】:

          【解决方案6】:

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-11-21
            • 1970-01-01
            • 2013-11-01
            • 1970-01-01
            • 2018-11-22
            相关资源
            最近更新 更多