jetty启动分析
jetty启动命令:java -jar /usr/alibaba/jetty/start.jar -Djetty.home=/usr/alibaba/jetty --ini=/home/admin/deploy/jetty/start.ini
如果加上--help参数,则显示jetty启动的参数设置和配置设置,如下:
#java -jar /usr/alibaba/jetty/start.jar -Djetty.home=/usr/alibaba/jetty --ini=/home/admin/deploy/jetty/start.ini --help
properties={jetty.home=/usr/alibaba/install/jetty-distribution-7.2.0, path=/home/admin/deploy/jetty/lib/ext, OPTIONS=Server,ajp,ext,jmx,jsp,resources,websocket, lib=/home/admin/deploy/jetty/lib/ext}启动时所加载的配置选项。
Usage: java -jar start.jar [options...] [properties...] [configs...]
The start.jar builds a classpath and executes a main java class with
a classloader built from that classpath. By default the start.jar
mechanism is configured to start the jetty server, but it can be
configured to start any java main class. start.java里面会执行main.java这个类的main函数,由这个函数去读取start.conf配置,这个配置文件配置的jetty的相关环境变量和配置文件路径,以 及接下来需要执行的main类。
Command Line Options:
--help This help / usage information. 显示帮助信息
--version Print the version information for Jetty and
dependent jars, then exit. 显示jetty的版本
--list-options List the details of each classpath OPTION 显示启动需要的options信息,包括:=Server,ajp,ext,jmx,jsp,resources,websocket等,可以自己指定jetty启动的特性选项。每个option的实现是在独立的jar里,
这里配置上了jetty启动时就会去load这个jar包。
--list-config List the start.config file. 显示main类启动的配置,对应配置文件start.config
--dry-run Print the command line that the start.jar generates,
then exit. This may be used to generate command lines
when the start.ini includes -X or -D arguments. 显示用java -jar执行时的classpath路径等完整的java命令信息,在调试模式下有用 // Show Command Line to execute Jetty
--exec Run the generated command line (see --dry-run) in
a sub processes. This can be used when start.ini
contains -X or -D arguments, but creates an extra
JVM instance. 重新启动一个jvm进程 // Show Command Line to execute Jetty
--stop Stop the running Jetty instance. 停止jetty进程
--daemon Start in daemon mode with stderr and stdout
redirected to ${jetty.log}/start.log 是否开启守护进程模式
--config=<file> Specify an alternate start.config file.
The default is the start.config file inside
the start.jar. The default can also be specified
with the START system property. 重新指定config配置的路径
--ini=<file> Load command line arguments from a file. If
no --ini options are specified, then the
start.ini file will be read if it exists.
A --ini option with no file indicates that
start.ini should not be read. 启动jetty进程的配置
--pre=<file> Specify a configuration file that is to be processed
before any configuration files listed in start.ini 在加载start.ini里面执行的xml配置文件之前需要先加载的配置文件
System Properties: 启动时可以设置jetty的系统环境变量
These are set with a command line like "java -Dname=value ..." and are
accessible via the java.lang.System#getProperty(String) API.
Some key system properties are:
org.eclipse.jetty.util.log.class=[class] jetty加载的日志类
A Low Level Jetty Logger Implementation to use
(default: org.eclipse.jetty.util.log.Slf4jLog)
org.eclipse.jetty.util.log.DEBUG=[boolean] 是否打开日志debug模式
Debug logging for the stderr and javautil Loggers. Slf4j
and other loggers must be separately configured for debug.
(default: false)
org.eclipse.jetty.util.log.IGNORED=[boolean] 是否打开日志的ignored模式
Ignored exceptions are logged, independent of DEBUG settings
(default: false)
org.eclipse.jetty.util.log.SOURCE=[boolean]源代码的位置是否打印在错误日志上
The source location of logs is logged in the stderr Logger.
(default: false)
com.sun.management.jmxremote 是否开通JMX功能
Enable remote JMX management in Sun JVMS.
Properties: jetty启动的参数设置
These are set with a command line like "java -jar start.jar name=value"
and only affect the start mechanism. Some of these are defined in the
default start.config and will not be available if another configuration
file is used. NOTE: Not all properties are listed here:
path=[directory]
An additional class path element to add to the started class path. Typically
this is used to add directories of classes and/or resources
lib=[directory]
An additional library directory to add to the started class path. This must
be a (deep) directory of jars
STOP.PORT=[number]
The port to use to stop the running Jetty server.
Required along with STOP.KEY if you want to use the --stop option above.
STOP.KEY=[alphanumeric]
The passphrase defined to stop the server.
Requried along with STOP.PORT if you want to use the --stop option above.
DEBUG=true
Enable debug on the start mechanism and sets the
org.eclipse.jetty.util.log.stderr.DEBUG system property to true.
(default: false)
OPTIONS=[option,option,...] options列表
Enable classpath OPTIONS. Each options represents one or more jars
to be added to the classpath. The options are defined in
the start.config file and can be listed with --help or --list-options.
By convention, options starting with a capital letter (eg Server)
are aggregations of other available options. Available OPTIONS:
All
Client
Server
ajp
annotations
client
default
deploy
ext
jmx
jndi
jsp
jta
plus
policy
resources
rewrite
security
server
servlet
servlets
setuid
webapp
websocket
xml
Available Configurations: 默认配置列表
By convention, configuration files are kept in $JETTY_HOME/etc.
The known configuration files are:
etc/jetty-ajp.xml ajp支持配置
etc/jetty-bio-ssl.xml 阻塞io的ssl支持
etc/jetty-bio.xml 阻塞io
etc/jetty-contexts.xml contexts上下文配置支持
etc/jetty-debug.xml debug模式支持
etc/jetty-deploy.xml war部署支持
etc/jetty-fileserver.xml 文件服务器支持
etc/jetty-ipaccess.xml ip过滤支持
etc/jetty-jmx.xml jmx支持
etc/jetty-logging.xml 日志系统支持
etc/jetty-plus.xml 增强功能支持 jaas jndi
etc/jetty-policy.xml java的policy权限支持
etc/jetty-proxy.xml 代理服务器支持
etc/jetty-requestlog.xml cookie log日志支持
etc/jetty-rewrite.xml url rewrite支持
etc/jetty-ssl.xml ssl支持
etc/jetty-stats.xml 统计功能支持
etc/jetty-testrealm.xml 配置权限登录service
etc/jetty-webapps.xml web app功能支持
etc/jetty-xinetd.xml 使用inetd/xinetd配置jetty
etc/jetty.xml 基础配置
Defaults: 默认配置
A start.ini file may be used to specify default arguments to start.jar,
which are used if no command line arguments are provided and override
the defaults in the start.config file. If --ini options are provided on
the command line, then start.ini will no be read. The current start.ini
arguments are:
OPTIONS=Server,jsp,jmx,resources,websocket,ext
etc/jetty.xml
etc/jetty-deploy.xml
etc/jetty-webapps.xml
etc/jetty-contexts.xml
etc/jetty-testrealm.xml
main函数启动:org.eclipse.jetty.start.main 需要配置启动参数,start.ini的路径
config类的说明: The behaviour of Main is controlled by the <code>"org/eclipse/start/start.config
main类调用org.eclipse.jetty.start.config去加载所有的配置和配置文件,然后通过加载org/eclipse/start/start.config,这个配置文件里面有两行:
# The main class to run
org.eclipse.jetty.xml.XmlConfiguration.class
${start.class}.class property start.class
然后main类就回反射start.config配置的这个class类去执行它的main方法,
org.eclipse.jetty.xml.XmlConfiguration这个类就是具体解析jetty.xml等所有xml配置文件中配置,
都是关于server类的配置,这个类通过解析所有的xml文件通过反射去生成最终的org.eclipse.jetty.server.server(这个类就是jetty的服务器最核心的类)
XmlConfiguration.java的main方法代码:
public static void main( final String[] args ) //args就是start.ini里面配置的加载的xml文件
{
AccessController.doPrivileged( new PrivilegedAction()
{
public Object run()
{
try
{
Properties properties=null;
// Look for properties from start.jar
try
{
Class<?> config = XmlConfiguration.class.getClassLoader().loadClass("org.eclipse.jetty.start.Config");
properties=(Properties)config.getMethod("getProperties").invoke(null);
Log.debug("org.eclipse.jetty.start.Config properties = {}",properties); //加载config里面的环境变量
}
catch(NoClassDefFoundError e)
{
Log.ignore(e);
}
catch(ClassNotFoundException e)
{
Log.ignore(e);
}
catch(Exception e)
{
Log.warn(e);
}
// If no start.config properties, use clean slate
if (properties==null)
properties = new Properties();
jetty源码阅读总结1
最新推荐文章于 2019-11-26 17:21:22 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)