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

发布于 2024-10-04 06:07:21 字数 1135 浏览 5 评论 0原文

我可以使用 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();
  }

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

神爱温柔 2024-10-11 06:07:21

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

有一个 我的博客上有更大的文章

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.

迷爱 2024-10-11 06:07:21

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

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>
濫情▎り 2024-10-11 06:07:21

我知道这个问题不久前已经得到了回答。我无法从为我工作的本·麦肯那里得到答案。然而,我很幸运,通过添加直接向 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

wikiproject;
wikiproject;
<版本>1.0-SNAPSHOT

<属性>
    6.1.14




<依赖关系>
    <依赖关系>
        org.mortbay.jetty
        jetty;
        <版本>${jetty.version}
        <类型>罐子
    

    <依赖关系>
        org.mortbay.jetty
        jetty-util
        <版本>${jetty.version}
        <类型>罐子
    

    <依赖关系>
        org.mortbay.jetty
        jetty-plus;
        <版本>${jetty.version}
        <类型>罐子
    

    
    <依赖关系>
        org.mortbay.jetty
        jsp-2.1
        <版本>${jetty.version}
        <类型>罐子
    
    <依赖关系>
        org.mortbay.jetty
        jsp-api-2.1;
        <版本>${jetty.version}
        <类型>罐子
    

    <依赖关系>
        org.apache.ant;
        ant-antlr
        <版本>1.7.1
    


和我的开始类(我在文件夹 \src\test\java\com\company\wikiproject 中添加)

package com.company.wikiproject;
导入 org.mortbay.jetty.Connector;
导入 org.mortbay.jetty.Server;
导入 org.mortbay.jetty.bio.SocketConnector;
导入 org.mortbay.jetty.webapp.WebAppContext;
/**  
 * 用户:Jesper Rønn-Jensen  
 * 启动维基页面  
 */

公开课开始{

public static void main(String[] args) {
    服务器jettyServer = null;
    尝试 {
        jettyServer = 新服务器();

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

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

        jettyServer.setHandler(上下文);
        jettyServer.start();
    } catch(异常忽略){
        if (jettyServer != null) {
            尝试 {
                jettyServer.stop();
            } catch (异常 e1) {
                e1.printStackTrace();
            }
        }
    }
}

}

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

}

旧街凉风 2024-10-11 06:07:21

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

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>
我很坚强 2024-10-11 06:07:21

阅读此 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>

After reading this stackoverflow page (nice job) as well as http://wiki.eclipse.org/Jetty/Howto/Configure_JSP, I finally got this to work as well. Since my config is slightly different, I thought I'd contribute back. I have an embedded Jetty 8 installation without the 'javac' compiler, and I got it to work by using the eclipse compiler and setting the system property before creating the server, like this:

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

And using the following maven configuration:

<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>
寄居人 2024-10-11 06:07:21

Jetty 9.1.3,http://www.eclipse.org/jetty/ Documentation/current/configuring-jsp.html,并且仅添加 jetty-jsp 对我有用(加上网址中的 web.xml 配置)。无需从码头 groupId 外部(即 mortbay)添加 jar。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文