开发者社区> 问答> 正文

jfinal maven项目jetty如何使用支持jsp?报错

我在IntelliJ 搭建jfinal + maven环境,依赖如下:


<dependencies>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
    </dependency>

    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
    </dependency>

    <dependency>
      <groupId>javax.servlet.jsp.jstl</groupId>
      <artifactId>javax.servlet.jsp.jstl-api</artifactId>
      <version>1.2.1</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>com.jfinal</groupId>
      <artifactId>jfinal</artifactId>
      <version>2.2</version>
    </dependency>
   
<dependency>
      <groupId>com.jfinal</groupId>
      <artifactId>jetty-server</artifactId>
      <version>8.1.8</version>
      <!--<scope>provided</scope>-->
    </dependency>

  </dependencies>

  <build>
    <plugins>
      
      <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>9.3.10.v20160621</version>
        <configuration>
          <httpConnector>
            <port>8080</port>
          </httpConnector>
          <stopPort>9966</stopPort>
          <stopKey>stop</stopKey>
          <scanIntervalSeconds>5</scanIntervalSeconds>
          <webApp>
            <contextPath>/</contextPath>
          </webApp>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>
    </plugins>
  </build>



启动类:



package com.ef.demo.common;
import com.jfinal.core.JFinal;
public class Stratup {

    public static void main(String[] args) {
        JFinal.start("src/main/webapp", 8080, "/", 5);
    }
}



Controller:



public class IndexController extends Controller {
    public void index(){
//        renderText("hello JFinal world!");//正常
        renderJsp("index.jsp");//报错: JSP support not configured
    }
}


以上配置启动正常但是访问jsp页面会报错:

JSP support not configured

我有2个问题:


1. 如何配置在开发环境(IntelliJ IDEA)maven+jetty+jsp(我已经尝试把官demo的jar的依赖都加进去了但还是不能renderJSP  )的依赖?

2. pom.xml 里面 jetty server的依赖的groupid用com.jfinal和用org.eclipse.jetty区别是什么?(如果把jfinal的jettey改成相同版本的eclipse的jetty则启动报错: Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/webapp/WebAppContext )

@JFinal 或者谁能帮忙? 谢谢

展开
收起
爱吃鱼的程序员 2020-06-09 12:46:10 700 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    Idea你就用你的 jetty-maven-plugin插件启动就好了。

    pom里面 jetty-serverscope加上另外把JFinal和 junit留下,其他的去掉。加上这个:

    <dependency><groupId>javax.servlet</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency>




    启动方法看图。

    下面给出dependency:

    <!--JettyJSP:根据DependencyHierarchy视图拆分成了七个dependency,-方便项目以及便于导出war的在jetty与tomcat间无缝迁移-Dependencies:http://mvnrepository.com/artifact/org.eclipse.jetty/jetty-jsp<dependency><groupId>org.eclipse.jetty</groupId><artifactId>jetty-jsp</artifactId><version>8.1.8.v20121106</version><scope>provided</scope></dependency>--><dependency><!--jetty-server-8.1.8开发时JSP支持--><groupId>org.eclipse.jetty.orbit</groupId><artifactId>javax.servlet.jsp</artifactId><version>2.2.0.v201112011158</version><scope>provided</scope></dependency><dependency><!--jetty-server-8.1.8开发时JSP支持--><groupId>org.eclipse.jetty.orbit</groupId><artifactId>org.apache.jasper.glassfish</artifactId><version>2.2.2.v201112011158</version><scope>provided</scope></dependency><dependency><!--jetty-server-8.1.8开发时JSP支持--><groupId>org.eclipse.jetty.orbit</groupId><artifactId>javax.el</artifactId><version>2.2.0.v201108011116</version><scope>provided</scope></dependency><dependency><!--jetty-server-8.1.8开发时JSP支持--><groupId>org.eclipse.jetty.orbit</groupId><artifactId>com.sun.el</artifactId><version>2.2.0.v201108011116</version><scope>provided</scope></dependency><dependency><!--jetty-server-8.1.8开发时JSP支持--><groupId>org.eclipse.jetty.orbit</groupId><artifactId>org.eclipse.jdt.core</artifactId><version>3.7.1</version><scope>provided</scope></dependency><dependency><!--JSTL支持--><groupId>org.eclipse.jetty.orbit</groupId><artifactId>javax.servlet.jsp.jstl</artifactId><version>1.2.0.v201105211821</version><exclusions><!--避免导出servletjar包--><exclusion><groupId>org.eclipse.jetty.orbit</groupId><artifactId>javax.servlet</artifactId></exclusion></exclusions></dependency><dependency><!--JSTL支持--><groupId>org.eclipse.jetty.orbit</groupId><artifactId>org.apache.taglibs.standard.glassfish</artifactId><version>1.2.0.v201112081803</version><exclusions><!--避免导出servletjar包--><exclusion><groupId>org.eclipse.jetty.orbit</groupId><artifactId>javax.servlet</artifactId></exclusion></exclusions>



      特别注意,其实最简单的方式,只需要第一个 jetty-jsp即可,但war包打出来会包含很多jetty的东东,而通常你的生产环境用的是tomcat,所以又需要去掉这些东东,所以上面做了一个拆分,并将scope全部声明为了provided,打war包时不会包含这些东东。




    引用来自“JFinal”的评论

    下面给出dependency:

    <!--JettyJSP:根据DependencyHierarchy视图拆分成了七个dependency,-方便项目以及便于导出war的在jetty与tomcat间无缝迁移-Dependencies:http://mvnrepository.com/artifact/org.eclipse.jetty/jetty-jsp<dependency><groupId>org.eclipse.jetty</groupId><artifactId>jetty-jsp</artifactId><version>8.1.8.v20121106</version><scope>provided</scope></dependency>--><dependency><!--jetty-server-8.1.8开发时JSP支持--><groupId>org.eclipse.jetty.orbit</groupId><artifactId>javax.servlet.jsp</artifactId><version>2.2.0.v201112011158</version><scope>provided</scope></dependency><dependency><!--jetty-server-8.1.8开发时JSP支持--><groupId>org.eclipse.jetty.orbit</groupId><artifactId>org.apache.jasper.glassfish</artifactId><version>2.2.2.v201112011158</version><scope>provided</scope></dependency><dependency><!--jetty-server-8.1.8开发时JSP支持--><groupId>org.eclipse.jetty.orbit</groupId><artifactId>javax.el</artifactId><version>2.2.0.v201108011116</version><scope>provided</scope></dependency><dependency><!--jetty-server-8.1.8开发时JSP支持--><groupId>org.eclipse.jetty.orbit</groupId><artifactId>com.sun.el</artifactId><version>2.2.0.v201108011116</version><scope>provided</scope></dependency><dependency><!--jetty-server-8.1.8开发时JSP支持--><groupId>org.eclipse.jetty.orbit</groupId><artifactId>org.eclipse.jdt.core</artifactId><version>3.7.1</version><scope>provided</scope></dependency><dependency><!--JSTL支持--><groupId>org.eclipse.jetty.orbit</groupId><artifactId>javax.servlet.jsp.jstl</artifactId><version>1.2.0.v201105211821</version><exclusions><!--避免导出servletjar包--><exclusion><groupId>org.eclipse.jetty.orbit</groupId><artifactId>javax.servlet</artifactId></exclusion></exclusions></dependency><dependency><!--JSTL支持--><groupId>org.eclipse.jetty.orbit</groupId><artifactId>org.apache.taglibs.standard.glassfish</artifactId><version>1.2.0.v201112081803</version><exclusions><!--避免导出servletjar包--><exclusion><groupId>org.eclipse.jetty.orbit</groupId><artifactId>javax.servlet</artifactId></exclusion></exclusions>



      特别注意,其实最简单的方式,只需要第一个 jetty-jsp即可,但war包打出来会包含很多jetty的东东,而通常你的生产环境用的是tomcat,所以又需要去掉这些东东,所以上面做了一个拆分,并将scope全部声明为了provided,打war包时不会包含这些东东。




    回复 @如梦技术:嗯嗯intellij右边有很方便的菜单单击即可如图,点一下那个红框框里面的就好,不用自己敲命令。

    @如梦技术,问一个相关问题intellij如何设置自动编译,像这样设置无效:http://www.360doc.com/content/14/1110/08/16002580_423959393.shtml

    否则每次改java需要手动点make麻烦

    引用来自“sucanber”的评论

    @如梦技术,问一个相关问题intellij如何设置自动编译,像这样设置无效:http://www.360doc.com/content/14/1110/08/16002580_423959393.shtml

    否则每次改java需要手动点make麻烦

    这里再补充一下,新版本jfinal在用整合的 Jetty启动时,需要使用下面的depencency,前面给出的不再适用:

    <!--jspsupportbyjetty--><dependency><groupId>org.eclipse.jetty</groupId><artifactId>jetty-jsp</artifactId><version>8.1.8.v20121106</version><scope>provided</scope></dependency>

    如果是IDEA下开发,要将scope改成compile,在打war包时注意要再改回来成为provided,独立部署用的容器大多都有jsp支持的jar包

    2020-06-09 12:46:28
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Java Spring Boot开发实战系列课程【第15讲】:Spring Boot 2.0 API与Spring REST Docs实战 立即下载
Java Spring Boot开发实战系列课程【第7讲】:Spring Boot 2.0安全机制与MVC身份验证实战(Java面试题) 立即下载
Java Spring Boot开发实战系列课程【第6讲】:Spring Boot 2.0实战MyBatis与优化(Java面试题) 立即下载

相关镜像