---
title: "在eclipse中运行jetty需要配置的几个点"
author: "pesome"
date: "2008-09-03T18:36:43Z"
tags: []
slug: "eclipse-jetty"
draft: false
lastmod: "2008-09-03T18:36:43Z"
id: 236283
url: "https://pesome.iteye.com/blog/236283"
---

在前面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-&gt;java-&gt;Build Path-&gt;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），是快速开发中很好的实践。