首页
http://dist.codehaus.org/jetty/ 选择下载版本 下载,下载下来之后 解压
2、我是windows 启动命令 java -jar start.jar etc/jetty.xml
默认8080 端口 访问http://localhost:8080/test/ test自带工程 出现welcome页面
把自己的项目拷贝到D:\\jetty-6.1.0\\webapps (我的是d 盘 ,自己的位置自己改下)执行启动命令 然后访问
制作Jetty bat启动文件
@ECHO OFF
D:
cd D:\\jetty-6.1.0
echo 启动Jetty...
pause
java -jar start.jar etc/jetty.xml
3、Jetty服务配置etc\\jetty.xml
修改访问端口:
其它配置http://jimichan.iteye.com/blog/601186
=====以上是外部jetty容器中配置=====下面是项目工程中的配置及问题=====
1、jetty跟meven的结合pom.xml中的配置
2、Jetty代码运行方式
public class ServerStart {
static String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
static String subPath = "src/main/webapp";
static String etcPath = "etc/webdefault.xml";
public static void main(String[] args) throws Exception {
System.out.println("正在启动....................");
long begin = System.currentTimeMillis();
Connector connector = new SelectChannelConnector();
connector.setPort(Integer.getInteger("jetty.port", 80).intValue());
WebAppContext webapp = new WebAppContext(getPath()+subPath, "/");
webapp.setDefaultsDescriptor(getPath()+etcPath);
Server server = new Server();
server.setConnectors(new Connector[] { connector });
server.setHandler(webapp);
server.start();
System.out.println("Jetty Server started”);
}
private static String getPath(){
if(path.indexOf("/") == 0){
path = path.substring(1, path.length());
}
path = path.replace("target/test-classes/", "");
return path;
}
}
启动成功
3、注意:当启动jetty后修改不了静态html,js后无法保存,无论是在Eclipse里面保存还是在外部都无法保存。jetty 缓存了静态的html,js 和css等,不能被修改,但是JSP文件是可以修改的。
修改web.xml加入下面文件,再次重新启动,改html,js没问题
最后注意:jetty中的项目放入tomcat中运行很多时候会出现错误