`
wking_forever
  • 浏览: 61571 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

jetty配置

 
阅读更多
package jetty;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mortbay.jetty.Server;
import org.mortbay.xml.XmlConfiguration;
import org.springframework.util.Log4jConfigurer;
import org.xml.sax.SAXException;


public class JServer {
	
  private static Log LOG = LogFactory.getLog(JServer.class);
  
  public final static String JETTYLOG = "log1234" ;//自己设定
  public final static String JETTYHOME = "./WebContent" ;
  
  public static void main(String[] args) {
  Server server = new Server();
  XmlConfiguration configuration = null;
  System.setProperty("jetty.logs", JETTYLOG);
  System.setProperty("jetty.home", JETTYHOME);
  try {
	Log4jConfigurer.initLogging("./WebContent/WEB-INF/log4j.properties");
	configuration = new XmlConfiguration(new File( "./WebContent/WEB-INF/jetty.xml").toURI().toURL());
	configuration.configure(server);
	server.start();
	if(server.isStarting()){
		LOG.info("starting");
	}
	if(server.isStarted()){
		LOG.info("started");
	}
	if(server.isRunning()){
		LOG.info("Running");
	}
    } catch (MalformedURLException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
	} catch (SAXException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
}
}

<?xml version="1.0"?>
<Configure id="Server" class="org.mortbay.jetty.Server">

	<!-- =========================================================== -->
	<!-- Server Thread Pool -->
	<!-- =========================================================== -->
	<Set name="ThreadPool">
		<New class="org.mortbay.thread.QueuedThreadPool">
			<!-- initial threads set to 10 -->
			<Set name="minThreads">10</Set>

			<!-- the thread pool will grow only up to 200 -->
			<Set name="maxThreads">200</Set>

			<!-- indicates that having 20 and below, the pool will be considered low 
				on threads -->
			<Set name="lowThreads">20</Set>

			<!-- The number of queued jobs (or idle threads) needed before the thread 
				pool is grown (or shrunk) -->
			<Set name="SpawnOrShrinkAt">2</Set>
		</New>
	</Set>

	<!-- =========================================================== -->
	<!-- Set connectors -->
	<!-- =========================================================== -->

	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- To add a HTTPS SSL connector -->
	<!-- mixin jetty-ssl.xml: -->
	<!-- java -jar start.jar etc/jetty.xml etc/jetty-ssl.xml -->
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<Call name="addConnector">
        <Arg>
            <New class="org.mortbay.jetty.nio.SelectChannelConnector">
                <!-- the ip address or domain to bind -->
                <Set name="host">
                    <SystemProperty name="jetty.host" />
                </Set>

                <!-- the port to use/bind, defaults to 8080 if property not set -->
                <Set name="port">
                    <SystemProperty name="jetty.port" default="7979" />
                </Set>

                <!-- the time in milliseconds when a connection is considered idle -->
                <Set name="maxIdleTime">300000</Set>

                <!-- the number of acceptors (their job is to accept the connection and dispatch to thread pool) -->
                <Set name="Acceptors">2</Set>

                <!-- should the connection statistics be turned on? (Not advisable in production) -->
                <Set name="statsOn">false</Set>

                <!-- the confidential port -->
                <Set name="confidentialPort">8443</Set>

                <!-- indicates the minimum number of connections when the server is considered low on resources -->
                <Set name="lowResourcesConnections">20000</Set>

                <!-- when low on resources, this indicates the maximum time (milliseconds) a connection must be idle to not be closed -->
                <Set name="lowResourcesMaxIdleTime">5000</Set>
            </New>
        </Arg>
    </Call>

	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- To add a HTTP blocking connector -->
	<!-- mixin jetty-bio.xml: -->
	<!-- java -jar start.jar etc/jetty.xml etc/jetty-bio.xml -->
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

	<!-- =========================================================== -->
	<!-- Set handler Collection Structure -->
	<!-- =========================================================== -->
	<Set name="handler">
		<!-- the collection of handlers that will handle the request -->
		<New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection">
			<Set name="handlers">
				<Array type="org.mortbay.jetty.Handler">
					<!-- primarily handles the request and maps the request to a ContextHandler -->
					<Item>
						<New id="Contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection" />
					</Item>

					<!-- The default handler ... handles the request if not yet handled -->
					<Item>
						<New id="DefaultHandler" class="jetty.MyHandler" />
					</Item>

					<!-- The handler for your request logs -->
					<Item>
						<New id="RequestLog" class="org.mortbay.jetty.handler.RequestLogHandler" />
					</Item>
				</Array>
			</Set>
		</New>
	</Set>

	<!-- =========================================================== -->
	<!-- Configure the context deployer -->
	<!-- A context deployer will deploy contexts described in -->
	<!-- configuration files discovered in a directory. -->
	<!-- The configuration directory can be scanned for hot -->
	<!-- deployments at the configured scanInterval. -->
	<!-- -->
	<!-- This deployer is configured to deploy contexts configured -->
	<!-- in the $JETTY_HOME/contexts directory -->
	<!-- -->
	<!-- =========================================================== -->
	<Call name="addLifeCycle">
		<Arg>
			<New class="org.mortbay.jetty.deployer.ContextDeployer">
				<!-- the ContextHandlerCollection to modify once a webapp is added or 
					removed (Allows Hot Deployment) -->
				<Set name="contexts">
					<Ref id="Contexts" />
				</Set>

				<!-- the directory which will contain your context.xml files -->
				<Set name="configurationDir">
					file:///<SystemProperty name="jetty.home" default="." />/contexts
				</Set>

				<!-- the interval in milliseconds to periodically scan the configurationDir -->
				<Set name="scanInterval">5</Set>
			</New>
		</Arg>
	</Call>

	<!-- =========================================================== -->
	<!-- Configure the webapp deployer. -->
	<!-- A webapp deployer will deploy standard webapps discovered -->
	<!-- in a directory at startup, without the need for additional -->
	<!-- configuration files. It does not support hot deploy or -->
	<!-- non standard contexts (see ContextDeployer above). -->
	<!-- -->
	<!-- This deployer is configured to deploy webapps from the -->
	<!-- $JETTY_HOME/webapps directory -->
	<!-- -->
	<!-- Normally only one type of deployer need be used. -->
	<!-- -->
	<!-- =========================================================== -->
	<Call name="addLifeCycle">
		<Arg>
			<New class="org.mortbay.jetty.deployer.WebAppDeployer">
				<!-- the ContextHandlerCollection to add the webapps to -->
				<Set name="contexts">
					<Ref id="Contexts" />
				</Set>

				<!-- the directory where all the webapps are located (can be exploded 
					or packaged as war -->
				<Set name="webAppDir">
					<SystemProperty name="jetty.home" default="." />
				</Set>

				<!-- indicates whether to lookup/load from the parent class loader first -->
				<Set name="parentLoaderPriority">false</Set>

				<!-- indicates whether to extract the webapp if it is packaged as a war -->
				<Set name="extract">true</Set>

				<!-- indicates whether a deployed webapp on a certain contextPath should 
					have a duplicate webapp deployment -->
				<Set name="allowDuplicates">false</Set>

				<!-- the default descriptor to use to be applied before a webapps' web.xml -->
				<Set name="defaultsDescriptor">
					<SystemProperty name="jetty.home" default="." />/WEB-INF/web.xml
				</Set>

			</New>
		</Arg>
	</Call>

	<!-- =========================================================== -->
	<!-- Configure Authentication Realms -->
	<!-- Realms may be configured for the entire server here, or -->
	<!-- they can be configured for a specific web app in a context -->
	<!-- configuration (see $(jetty.home)/contexts/test.xml for an -->
	<!-- example). -->
	<!-- =========================================================== -->
	<Set name="UserRealms">
		<Array type="org.mortbay.jetty.security.UserRealm">
			<Item>
				<!-- this realm uses a properties file to store/read the user/password/roles -->
				<New class="org.mortbay.jetty.security.HashUserRealm">
					<!-- the name of the realm -->
					<Set name="name">Test Realm</Set>

					<!-- the location of the property file to load from -->
					<!-- <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set> -->
					<!-- the interval in seconds to periodically scan for any changes and 
						refresh/reload if changed -->
					<Set name="refreshInterval">0</Set>
				</New>
			</Item>
		</Array>
	</Set>

	<!-- =========================================================== -->
	<!-- Configure Request Log -->
	<!-- Request logs may be configured for the entire server here, -->
	<!-- or they can be configured for a specific web app in a -->
	<!-- contexts configuration (see $(jetty.home)/contexts/test.xml -->
	<!-- for an example). -->
	<!-- =========================================================== -->
	<Ref id="RequestLog">
		<Set name="requestLog">
			<New id="RequestLogImpl" class="org.mortbay.jetty.NCSARequestLog">
				<!-- the output file name of the log file. Name of the file will be date 
					formatted -->
				<Set name="filename">
					<SystemProperty name="jetty.logs" default="./log" />/yyyy_mm_dd.request.log
				</Set>

				<!-- the date format -->
				<Set name="filenameDateFormat">yyyy_MM_dd</Set>

				<!-- the days to retain the log file -->
				<Set name="retainDays">90</Set>

				<!-- indicates if the new lines should be appended on an existing log 
					file -->
				<Set name="append">true</Set>

				<!-- indicates if the lines logged to the file will be in extended format -->
				<Set name="extended">true</Set>

				<!-- Indicates if the cookie logs should be included in the log file -->
				<Set name="logCookies">false</Set>

				<!-- the timezone of the log -->
				<Set name="LogTimeZone">GMT</Set>
			</New>
		</Set>
	</Ref>

	<!-- =========================================================== -->
	<!-- extra options -->
	<!-- =========================================================== -->

	<!-- Stops the server when ctrl+c is pressed (registers to Runtime.addShutdownHook) -->
	<Set name="stopAtShutdown">true</Set>

	<!-- send the server version in the response header? -->
	<Set name="sendServerVersion">true</Set>

	<!-- send the date header in the response header? -->
	<Set name="sendDateHeader">true</Set>

	<!-- allows requests(prior to shutdown) to finish gracefully -->
	<Set name="gracefulShutdown">1000</Set>
</Configure>

package jetty;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mortbay.jetty.servlet.ServletHandler;

public class MyHandler extends ServletHandler{

	@Override
	public void handle(String target, HttpServletRequest request, HttpServletResponse response, int type) throws IOException,
			ServletException {
		// TODO Auto-generated method stub
		System.out.println("handling");
		PrintWriter pw = response.getWriter();
		
        pw.println("w de 我的  goodbye");
        pw.flush();
        pw.close();
	}
 
}

log4j.rootLogger=INFO,CONSOLE,rolling

#log4j.logger.org.springframework=ERROR
#log4j.logger.org.apache=ERROR

log4j.logger.com.ssc.rdr=INFO

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.Threshold=DEBUG 
log4j.appender.CONSOLE.Target=System.out 
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout 
log4j.appender.CONSOLE.layout.ConversionPattern=%d - %c -%-4r [%t] %-5p %c %x - %m%n 
 
log4j.appender.rolling=org.apache.log4j.RollingFileAppender
log4j.appender.rolling.File=${jetty.logs}/rdrServer.log
log4j.appender.rolling.MaxBackupIndex=100
log4j.appender.rolling.MaxFileSize=10MB
log4j.appender.rolling.layout=org.apache.log4j.PatternLayout
log4j.appender.rolling.layout.ConversionPattern=%t %d{ABSOLUTE} %5p %c{1} - %m%n


<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>RDR</display-name>
 
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
</web-app>

jar包:
spring.jar
jetty-6.1.25.jar
jetty-util-6.1.25.jar
servlet-api-2.5-20081211.jar
commons-logging.jar
分享到:
评论

相关推荐

    Jetty配置支持https

    ### Jetty配置支持HTTPS及受信网站证书生成详解 #### 一、概述 在现代Web应用开发中,HTTPS协议已经成为标配。它不仅提供了安全的数据传输通道,还增强了用户对网站的信任度。对于使用Jetty服务器的项目来说,配置...

    jetty在eclipse中配置

    Jetty是一款轻量级、高性能的Java ...同时,提供的"eclipse中jetty配置.doc"文档可能包含更详细的步骤和注意事项,建议参考。而"jetty.rar"文件可能是包含Jetty服务器的示例或者额外配置文件,你可以根据需要解压查看。

    简单jetty配置

    本文将详细介绍如何进行简单的Jetty配置,包括解析`jetty.xml`、`pom.xml`和`jetty-env.xml`这三个关键配置文件。 首先,我们来看`jetty.xml`文件。这是Jetty的主配置文件,它定义了服务器的行为,如端口设置、...

    Jetty 配置 SSL

    **Jetty配置SSL步骤** 1. **获取SSL证书** - 可以从权威的证书颁发机构(如Verisign、Comodo等)购买SSL证书。 - 或者使用自签名证书,适用于测试环境。使用OpenSSL工具生成: ```shell openssl req -x509 -...

    Eclipse_Maven_Jetty配置

    ### Eclipse Maven Jetty 配置详解 #### 一、引言 在开发Web应用程序时,开发者经常需要在本地环境中配置并测试应用。Eclipse作为一款流行的集成开发环境(IDE),结合Maven(一种项目管理工具)与Jetty(一款开源...

    maven的打包、jetty配置、jetty事务检查、打包除resource之外的资源文件

    “jetty配置”是指对Jetty服务器进行定制以满足项目需求。Jetty是一个轻量级的Java Web容器,它可以快速地运行Servlet和Web应用。配置Jetty主要涉及修改jetty.xml或相关的context.xml文件,比如设置端口、添加部署、...

    Jetty9 配置使用HTTPS证书

    配置Jetty9服务器使用HTTPS证书的过程涉及多个步骤,包括申请证书、转换证书格式、以及配置Jetty服务器本身。以下详细描述这些步骤。 首先,申请证书部分通常需要借助第三方服务商,如阿里云、腾讯云等,这些服务商...

    tomcate和jetty虚拟目录配置方法

    下面我们将详细探讨Tomcat和Jetty的虚拟目录配置方法。 ### Tomcat虚拟目录配置 #### 1. 配置`server.xml` Tomcat的虚拟目录主要通过修改`conf/server.xml`文件来实现。在`&lt;Host&gt;`元素下添加`&lt;Context&gt;`元素来定义...

    maven +jetty 配置web工程

    本篇文章将详细探讨如何利用Maven与Jetty进行配置,以便高效地开发和运行Web工程。 首先,`Maven`是Apache软件基金会开发的项目管理工具,它通过一个统一的构建过程和依赖管理,简化了Java项目的构建、测试和部署。...

    Java Eclipse ee集合jetty和配置

    Eclipse EE 集合 Jetty 和配置 Eclipse 是一个功能强大且流行的集成开发环境(Integrated Development Environment,IDE),提供了许多插件和工具来支持各种编程语言和技术。其中,Eclipse EE(Enterprise Edition...

    apache+jetty负载配置案例

    本配置案例主要探讨如何将Apache与Jetty结合,实现负载均衡,以提高服务器性能和可用性。 一、Apache + Jetty 负载均衡原理 负载均衡是一种技术,通过分散网络流量到多个服务器,避免单个服务器过载,从而提高服务...

    jetty反相代理配置

    在Jetty中配置反向代理,我们需要以下步骤: 1. 添加依赖:确保你的项目已经包含了Jetty的proxy模块。在Maven项目中,可以在pom.xml文件中添加如下依赖: ```xml &lt;groupId&gt;org.eclipse.jetty &lt;artifactId&gt;...

    Intellij IDEA下建立maven管理的web项目,配置jetty热部署

    Intellij IDEA 下建立 Maven 管理的 Web 项目,配置 Jetty 热部署 在本文中,我们将学习如何使用 Intellij IDEA 建立一个基于 Maven 管理的 Web 项目,并配置 Jetty 热部署。 知识点 1:Intellij IDEA 中的 Maven ...

    Eclipse+maven+jetty环境配置

    Jetty配置 - **版本**: Jetty 5.1.14 - **下载地址**: [Jetty官方下载](http://dist.codehaus.org/jetty/jetty-5.1.x/jetty-5.1.14.tgz) - **解压**: 使用WinRAR解压缩到本地目录,例如:`C:\Jetty\jetty-5.1.14`。...

    JETTY启动文件配置方法.txt

    JETTY启动文件配置方法.txt

    IntelliJ IDEA使用tomcat和jetty配置详解

    在做jetty配置时候,IntelliJ IDEA会报错,是JMX(Java Management Extensions,即Java管理扩展)的错,上网查是说要在jetty的配置文件加上:--module=jmx,应该是用作允许IntelliJ IDEA调用jetty容器的声明。...

    Maven_Jetty_Plugin_配置指南(翻译)

    Maven Jetty Plugin 配置指南 Maven Jetty Plugin 是一个强大的插件,能够快速搭建 Web 应用程序,并提供了许多实用的功能。下面是 Maven Jetty Plugin 的配置指南: 一、插件简介 Maven Jetty Plugin 是基于 ...

    eclipse中配置使用jetty调试web项目

    在Eclipse这个强大的Java开发环境中,配置Jetty服务器来调试Web项目是一项常用的任务。Jetty是一个轻量级、高性能的开源HTTP服务器和Servlet容器,它允许开发者在本地环境快速部署和测试Web应用。本文将详细介绍如何...

    jetty的xml文件配置说明.pdf

    ### Jetty XML配置详解 Jetty是一款开源的高性能嵌入式Web服务器,广泛应用于Java Web应用的开发与部署。在Jetty中,XML配置是一种重要的配置方式,它提供了灵活且强大的配置机制,允许开发者通过XML文件来定义和...

Global site tag (gtag.js) - Google Analytics