我在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个问题:
Idea你就用你的jetty-maven-plugin插件启动就好了。
pom里面jetty-server scope加上另外把JFinal和junit留下,其他的去掉。加上这个:
<dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency>
启动方法看图。 ###### 下面给出 dependency:
<!-- Jetty JSP:根据 Dependency Hierarchy 视图拆分成了七个 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><!-- 避免导出 servlet jar 包 --> <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><!-- 避免导出 servlet jar 包 --> <exclusion> <groupId>org.eclipse.jetty.orbit</groupId> <artifactId>javax.servlet</artifactId> </exclusion> </exclusions>
特别注意,其实最简单的方式,只需要第一个 jetty-jsp 即可,但 war 包打出来会包含很多 jetty 的东东,而通常你的生产环境用的是 tomcat,所以又需要去掉这些东东,所以上面做了一个拆分,并将 scope 全部声明为了 provided,打 war 包时不会包含这些东东。
######
<!-- Jetty JSP:根据 Dependency Hierarchy 视图拆分成了七个 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><!-- 避免导出 servlet jar 包 --> <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><!-- 避免导出 servlet jar 包 --> <exclusion> <groupId>org.eclipse.jetty.orbit</groupId> <artifactId>javax.servlet</artifactId> </exclusion> </exclusions>
特别注意,其实最简单的方式,只需要第一个 jetty-jsp 即可,但 war 包打出来会包含很多 jetty 的东东,而通常你的生产环境用的是 tomcat,所以又需要去掉这些东东,所以上面做了一个拆分,并将 scope 全部声明为了 provided,打 war 包时不会包含这些东东。
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> <dependency> <groupId>com.jfinal</groupId> <artifactId>jfinal</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-server</artifactId> <version>8.1.8.v20121106</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>运行mvn jetty:run命令即可启动工程
######回复 @如梦技术 : 嗯嗯 intellij 右边有很方便的菜单 单击即可######如图,点一下那个红框框里面的就好,不用自己敲命令。###### @如梦技术 , 问一个相关问题 intellij如何设置自动编译,像这样设置无效:http://www.360doc.com/content/14/1110/08/16002580_423959393.shtml
否则每次改java需要手动点make麻烦 ######
<!-- jsp support by jetty -->
<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 包版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。