在eclipse中运行jetty需要配置的几个点

 在前面springmvc 2.5的文章中提供了一个直接在eclipse中run和debug jetty的类,但这里有几个需要配置的地方,否则会出很多错误。我就是被折磨了很久,所以写下来,让大家少走弯路。

 

  1. Pom.xml文件,这里定义了需要的依赖

<dependency>
			<groupId>org.mortbay.jetty</groupId>
			<artifactId>org.mortbay.jetty</artifactId>
			<version>5.1.10</version>
		</dependency>
		<dependency>
			<groupId>tomcat</groupId>
			<artifactId>jasper-compiler</artifactId>
			<version>5.5.12</version>
		</dependency>
		<dependency>
			<groupId>tomcat</groupId>
			<artifactId>jasper-runtime</artifactId>
			<version>5.5.12</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.4</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.1.2</version>
		</dependency>
		<dependency>
			<groupId>taglibs</groupId>
			<artifactId>standard</artifactId>
			<version>1.1.2</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.0</version>
		</dependency>
		<dependency>
			<groupId>ant</groupId>
			<artifactId>ant</artifactId>
			<version>1.6.5</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>commons-el</groupId>
			<artifactId>commons-el</artifactId>
			<version>1.0</version>
		</dependency>

  jetty没有自己的compiler,所以需要依赖tomcat的jar。同时它需要ant的compiler,否则会报错:

java.lang.IllegalStateException: No Java compiler available
at org.apache.jasper.JspCompilationContext.createCompiler(JspCompilationContext.java:224)...

 

我被这个困扰了一阵,google到老外的论坛也没有解,还是自己看了JspCompilationContext的源代码,才发现使用的ant.

 

 2. eclipse中使用maven,需要配置M2_REPO这个变量,preference->java->Build Path->Classpath Variables中new 这个变量,并指向maven本机的respository即可。

 

3. Installed JRE配置, 需要使用JDK而不是JRE,要使用annotation需要是5以上版本。同时需在默认的JRE上edit,add external jar加入jdk所在目录的lib/tools.jar。否则在访问时也会报错

Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK
 at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:105)
 

能在eclipse中直接run和debug,方便了开发工作,而且可以和maven的结构很好配合(无需output指向WEB-INF/classes),是快速开发中很好的实践。


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值