---
title: "hive启动web程序流程"
author: "wankunde"
date: "2013-10-12T14:16:02Z"
tags: ["Web", "hive", "jetty"]
categories: ["开源软件"]
slug: "hive-web"
draft: false
lastmod: "2013-10-12T15:05:03Z"
id: 1955765
url: "https://wankunde.iteye.com/blog/1955765"
---

1.通过hwi service启动hwi.sh,在hwi.sh中到lib目录下找到hwi.jar和hwi.war，并执行主类org.apache.hadoop.hive.hwi.HWIServer  
2.在HWIServer中进入start方法，设置好host和port变量，默认为0.0.0.0:9999，通过

```
webServer = ShimLoader.getJettyShims().startServer(listen, port);
  webServer.addWar(hwiWARFile.toString(), "/hwi"); //hwiWARFile 为war包的文件名
webServer.start();
  webServer.join();
```

来启动jetty服务器。  
3.ShimLoader为shims包中的common文件夹下的工具类，他通过反射来实例化工具类对象，这里实例化一个JettyShims对象。  
JettyShims封装了对Jetty服务器的一些操作，可以根据不同的Hadoop的版本（一个HashMap）生成相应的操作实例。

```
public interface JettyShims {
  Server startServer(String listen, int port) throws IOException;
  /**
  * Server.
  *
  */
  interface Server {
  void addWar(String war, String mount);
  void start() throws Exception;
  void join() throws InterruptedException;
  void stop() throws Exception;
  }
  }
```

这里我们一个Jetty20SShims实例为准，在startServer中我们先实例化一个Server对象，  
private static class Server extends org.mortbay.jetty.Server implements JettyShims.Server  
然后

```
public void setupListenerHostPort(String listen, int port)
  throws IOException {
SocketConnector connector = new SocketConnector();
  connector.setPort(port);
  connector.setHost(listen);
  this.addConnector(connector);
  }
```

至此，jetty服务器已经在指定的地址和端口启动了，OK.

使用JettyServer工具类进行测试。

public static void main(String\[] args) throws Exception {

JettyServer js = new JettyServer();

js.setupListenerHostPort("localhost", 9999);

js.addWar("D:\\\\软件安装源程序\\\\Java\\\\eclipse\_jee\\\\mywar.war", "/mywar");

js.start();

}

添加jetty-6.1.26.jar，jetty-util-6.1.26.jar，servlet-api-2.5-6.0.1.jar三个包，

此时可以即可访问启动的web程序了。

jetty7及以后版本由eclipse进行托管，使用方法有所改变。

&lt;a href="http://download.eclipse.org/jetty/"&gt;http://download.eclipse.org/jetty/&lt;/a&gt;

jetty6 下载地址，目前不知道以后还会不会提供下载。

&lt;a href="http://dist.codehaus.org/jetty/jetty-6.1.26/jetty-6.1.26.zip"&gt;http://dist.codehaus.org/jetty/jetty-6.1.26/jetty-6.1.26.zip&lt;/a&gt;

Jetty Version Comparison Table

Version Servlet Java Namespace Licenses Site Status Jetty 9 Servlet 3.0+ Java 1.7 org.eclipse.jetty.* [EPLv1](http://www.eclipse.org/legal/epl-v10.html) / [ASLv2](https://www.apache.org/licenses/LICENSE-2.0.html) [Eclipse.org](http://eclipse.org/jetty/) Alpha Milestones Jetty 8 Servlet 3.0 Java 1.6 org.eclipse.jetty.* [EPLv1](http://www.eclipse.org/legal/epl-v10.html) / [ASLv2](https://www.apache.org/licenses/LICENSE-2.0.html) [Eclipse.org](http://eclipse.org/jetty/) Stable Jetty 7 Servlet 2.5 Java 1.5 org.eclipse.jetty.* [EPLv1](http://www.eclipse.org/legal/epl-v10.html) / [ASLv2](https://www.apache.org/licenses/LICENSE-2.0.html) [Eclipse.org](http://eclipse.org/jetty/) Stable Jetty 6 Servlet 2.5 Java 1.4 org.mortbay.* [ASLv2](https://www.apache.org/licenses/LICENSE-2.0.html) [Codehaus.org](http://jetty.codehaus.org/) End of Life / Nov 2010

其他问题：

启动jetty后，访问jsp页面，出现一下错误：

HTTP ERROR: 500

JSP support not configured

RequestURI=/capaa/WEB-INF/jsp/error/500.jsp

&lt;a href="http://jetty.mortbay.org/"&gt;Powered by Jetty://&lt;/a&gt;

原因：是应为没有加载jetty用来解释jsp的jar包。加载进来就可以了。

解决办法：project--点右键－－－property---java build path----Add Extenters Jars

选择jetty6.1--lib--jsp2.1---\*.jar添加即可