JettyRun 是如何跑WEB PROJECT的.

首先, 我们应该要准备好 jetty包:

compile 'org.mortbay.jetty:jetty:6.1.26' 我是用的gradle1.6 比较老了, 懒得升级. 这个与下载包木有关系, 你可以不关心.

看看我的包结构:

很好.  在看看我写的MAIN方法:


package com.vernon.file;

import com.vernon.file.core.Config;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;
import org.mortbay.thread.QueuedThreadPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created with IntelliJ IDEA.
 * User: chenyuan
 * Date: 1/3/14
 * Time: 9:28
 * To change this template use File | Settings | File Templates.
 */
public class JettyRun {

    private static final Logger LOGGER = LoggerFactory.getLogger(JettyRun.class);
    private static final int WEB_SERVER_PORT = Config.INSTANCE.getInt("web_server_port", 80);

    public void start() throws Exception {
        Server server = new Server();
        // 线程
        QueuedThreadPool threadPool = new QueuedThreadPool();
        threadPool.setMaxThreads(300);
        server.setThreadPool(threadPool);
        // 连接
        Connector connector = new SelectChannelConnector();
        connector.setPort(WEB_SERVER_PORT);
        server.setConnectors(new Connector[]{connector});
        //Handler
        WebAppContext context = new WebAppContext("src/main/webapp","/");
        context.setDescriptor("src/main/webapp/WEB-INF/web.xml");
        context.setResourceBase("src/main/webapp");
        context.setDisplayName("trunk");
        context.setClassLoader(Thread.currentThread().getContextClassLoader());
        context.setParentLoaderPriority(true);

        LOGGER.info(context.getContextPath());
        LOGGER.info(context.getDescriptor());
        LOGGER.info(context.getResourceBase());
        LOGGER.info(context.getBaseResource().toString());

        server.setHandler(context);
        server.start();
    }


    public static void main(String[] args) throws Exception {
        new JettyRun().start();
    }
}



运行main方法, 就可以跑起来了. 



转载于:https://my.oschina.net/vernon/blog/220178

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值