版本 | Year | Home | JVM | 協議 | Servlet | JSP | 狀態 |
---|---|---|---|---|---|---|---|
9.3php |
2015html |
Eclipsejava |
1.8web |
HTTP/1.1 (RFC 7230), HTTP/2 (RFC 7540), redis WebSocket (RFC 6455, JSR 356), FastCGIspring |
3.1shell |
2.3數據庫 |
穩定版本 |
9.2apache |
2014數組 |
Eclipse |
1.7 |
HTTP/1.1 RFC2616, javax.websocket, SPDY v3 |
3.1 |
2.3 |
穩定版本 |
8 |
2009- |
Eclipse/Codehaus |
1.6 |
HTTP/1.1 RFC2616, WebSocket RFC 6455, SPDY v3 |
3.0 |
2.2 |
珍貴版本 |
7 |
2008- |
Eclipse/Codehaus |
1.5 |
HTTP/1.1 RFC2616, WebSocket RFC 6455, SPDY v3 |
2.5 |
2.1 |
珍貴版本 |
6 |
2006-2010 |
Codehaus |
1.4-1.5 |
HTTP/1.1 RFC2616 |
2.5 |
2.0 |
已經做廢 |
5 |
2003-2009 |
Sourceforge |
1.2-1.5 |
HTTP/1.1 RFC2616 |
2.4 |
2.0 |
已經做廢 |
4 |
2001-2006 |
Sourceforge |
1.2, J2ME |
HTTP/1.1 RFC2616 |
2.3 |
1.2 |
遠古時期 |
3 |
1999-2002 |
Sourceforge |
1.2 |
HTTP/1.1 RFC2068 |
2.2 |
1.1 |
石器時代 |
2 |
1998-2000 |
Mortbay |
1.1 |
HTTP/1.0 RFC1945 |
2.1 |
1.0 |
傳說級別 |
1 |
1995-1998 |
Mortbay |
1.0 |
HTTP/1.0 RFC1945 |
- |
- |
神話級別 |
JSR | 名稱 | jetty-9.1.x是否包含 | 支持插件 |
---|---|---|---|
JSR 340 |
Servlet Specification API 3.1 |
Yes |
|
JSR 344 |
Java Server Faces 2.2 (JSF) |
No |
Yes, Mojarra or MyFaces |
JSR 245 / JSR 341 |
Java Server Pages 2.3/Java Expression Language 3.0 (JSP/EL) |
Yes |
Yes |
JSR 52 |
Java Standard Tag Library 1.2 (JSTL) |
Yes |
Yes |
JSR 45 |
Debugging Support for Other Languages 1.0 |
Yes (via JSP) |
Yes (via JSP) |
JSR 346 |
Contexts and Dependency Injection for the JavaEE Platform 1.1 (Web Beans) |
No |
Yes, Weld |
JSR 330 |
Dependency Injection for Java 1.0 |
No |
Yes as part of a CDI implementation, Weld |
JSR 316 |
Managed Beans 1.0 |
No |
Yes, as part of another technology |
JSR 345 |
Enterprise JavaBeans 3.2 Lite |
No |
|
JSR 338 |
Java Persistance 2.1 (JPA) |
No |
Yes, eg Hibernate |
JSR 250 |
Common Annotations for the Java Platform 1.2 |
Yes |
Partially (for non-core Servlet Spec annotations) |
JSR 907 |
Java Transaction API 1.2 (JTA) |
Yes |
Yes |
JSR 349 |
Bean Validation 1.1 |
No |
Yes as part of another technology eg JSF, or a stand-alone implementation such as Hiberate Validator |
JSR 339 |
Java API for RESTful Web Services 2.0 (JAX-RS) |
No |
|
JSR 356 |
Java API for Websocket 1.0 |
Yes |
No |
JSR 353 |
Java API for JSON Processing 1.0 (JSON-P) |
No |
Yes, eg JSON-P reference implementation |
JSR 318 |
Interceptors 1.2 |
No |
Yes as part of a CDI implementation |
表格 1.3. Java EE 6 Web Profile
JSR | Name | Included with jetty-9.0.x | Pluggable |
---|---|---|---|
JSR 315 |
Servlet Specification API 3.0 |
Yes |
|
JSR 314 |
JavaServer Faces 2.0 (JSF) |
No |
Yes, for example, Mojarra or MyFaces |
JSR 245 |
JavaServer Pages 2.2/Java Expression Language 2.2 (JSP/EL) |
Yes |
Yes |
JSR 52 |
Java Standard Tag Library 1.2 (JSTL) |
Yes |
Yes |
JSR 45 |
Debugging Support for Other Languages 1.0 |
Yes (via JSP) |
Yes (via JSP) |
JSR 299 |
Contexts and Dependency Injection for the Java EE Platform 1.0 (Web Beans) |
No |
Yes, Weld or OpenWebBeans |
JSR 330 |
Dependency Injection for Java 1.0 |
No |
Yes as part of a CDI implementation, Weld |
JSR 316 |
Managed Beans 1.0 |
No |
Yes, as part of another technology. |
JSR 318 |
Enterprise JavaBeans 3.1 |
No |
Yes, OpenEJB |
JSR 317 |
Java Persistance 2.0 (JPA) |
No |
Yes, Hibernate |
JSR 250 |
Common Annotations for the Java Platform |
Yes |
Partially (for non-core Servlet Spec annotations) |
JSR 907 |
Java Transaction API (JTA) |
Yes |
Implementations are pluggable, such as Atomikos, JOTM, Jencks (Geronimo Transaction Manager) |
JSR 303 |
Bean Validation 1.0 |
No |
Yes as part of another technology (JSF), or a stand-alone implementation such as Hiberate Validator |
<dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-project</artifactId> <version>${project.version}</version> </dependency>
<dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-project</artifactId> <version>${project.version}</version> <classifier>version</classifier> <type>txt</type> </dependency>
表格 2.1. Contents
Location | Description |
---|---|
license-eplv10-aslv20.html |
Jetty的許可文件 |
README.txt |
有用的開始信息 |
VERSION.txt |
版本信息 |
bin/ |
存放在Unix系統下運行的shell腳本 |
demo-base/ |
一個可運行包含示例web應用的Jetty服務器基目錄 |
etc/ |
Jetty的配置文件 |
lib/ |
Jetty運行所必須的jar文件 |
logs/ |
日誌 |
modules/ |
各個模塊 |
notice.html |
許可信息等 |
resources/ |
包含新增到classpath配置文件夾,如log4j.properties |
start.ini |
存放啓動信息 |
start.jar |
運行Jetty的jar |
webapps/ |
一個用來存放運行在默認配置下的Jetty Web應用目錄 |
cd $JETTY_HOME
java -jar start.jar
若執行成功會輸出如下信息
2015-06-04 10:50:44.806:INFO::main: Logging initialized @334ms 2015-06-04 10:50:44.858:WARN:oejs.HomeBaseWarning:main: This instance of Jetty is not running from a separate {jetty.base} directory, this is not recommended. See documentation at http://www.eclipse.org/jetty/documentation/current/startup.html 2015-06-04 10:50:44.995:INFO:oejs.Server:main: jetty-9.3.0.v20150601 2015-06-04 10:50:45.012:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///opt/jetty-distribution-9.3.0.v20150601/webapps/] at interval 1 2015-06-04 10:50:45.030:INFO:oejs.ServerConnector:main: Started ServerConnector@19dfb72a{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} 2015-06-04 10:50:45.030:INFO:oejs.Server:main: Started @558ms
你能夠經過瀏覽器訪問http://localhost:8080.。然而在$JETTY_HOME/webapps目錄下並無部署任何web應用,因此你將會看到一個Jetty提供的404錯誤頁面,並不推薦在$JETTY_HOME下運行Jetty,而是建議運行一個Jetty基礎應用。錯誤頁面以下
> cd $JETTY_HOME/demo-base/ > java -jar $JETTY_HOME/start.jar
成功運行將有以下信息輸出:
2015-06-04 10:55:24.161:INFO::main: Logging initialized @308ms 2015-06-04 10:55:24.431:WARN::main: demo test-realm is deployed. DO NOT USE IN PRODUCTION! 2015-06-04 10:55:24.434:INFO:oejs.Server:main: jetty-9.3.0.v20150601 2015-06-04 10:55:24.457:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///opt/jetty-distribution-9.3.0.v20150601/demo-base/webapps/] at interval 1 2015-06-04 10:55:24.826:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@c038203{/,file:///opt/jetty-distribution-9.3.0.v20150601/demo-base/webapps/ROOT/,AVAILABLE}{/ROOT} 2015-06-04 10:55:24.929:WARN::main: test-jaas webapp is deployed. DO NOT USE IN PRODUCTION! 2015-06-04 10:55:24.978:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@46238e3f{/test-jaas,file:///tmp/jetty-0.0.0.0-8080-test-jaas.war-_test-jaas-any-9105214562680121772.dir/webapp/,AVAILABLE}{/test-jaas.war} 2015-06-04 10:55:25.162:WARN::main: async-rest webapp is deployed. DO NOT USE IN PRODUCTION! 2015-06-04 10:55:25.208:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@6b67034{/async-rest,[file:///tmp/jetty-0.0.0.0-8080-async-rest.war-_async-rest-any-1023939491558622183.dir/webapp/, jar:file:///tmp/jetty-0.0.0.0-8080-async-rest.war-_async-rest-any-1023939491558622183.dir/webapp/WEB-INF/lib/example-async-rest-jar-9.3.0.v20150601.jar!/META-INF/resources],AVAILABLE}{/async-rest.war} 2015-06-04 10:55:25.311:WARN::main: test-jndi webapp is deployed. DO NOT USE IN PRODUCTION! 2015-06-04 10:55:25.386:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@8b96fde{/test-jndi,file:///tmp/jetty-0.0.0.0-8080-test-jndi.war-_test-jndi-any-1692053319754270133.dir/webapp/,AVAILABLE}{/test-jndi.war} 2015-06-04 10:55:25.508:WARN::main: test-spec webapp is deployed. DO NOT USE IN PRODUCTION! 2015-06-04 10:55:25.594:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@69930714{/test-spec,[file:///tmp/jetty-0.0.0.0-8080-test-spec.war-_test-spec-any-5518740932795802823.dir/webapp/, jar:file:///tmp/jetty-0.0.0.0-8080-test-spec.war-_test-spec-any-5518740932795802823.dir/webapp/WEB-INF/lib/test-web-fragment-9.3.0.v20150601.jar!/META-INF/resources],AVAILABLE}{/test-spec.war} 2015-06-04 10:55:25.781:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@3eb7fc54{/proxy,file:///tmp/jetty-0.0.0.0-8080-xref-proxy.war-_xref-proxy-any-3068657547009829038.dir/webapp/,AVAILABLE}{/xref-proxy.war} 2015-06-04 10:55:25.786:INFO:oejsh.ContextHandler:main: Started o.e.j.s.h.MovedContextHandler@59662a0b{/oldContextPath,null,AVAILABLE} 2015-06-04 10:55:25.951:WARN::main: test webapp is deployed. DO NOT USE IN PRODUCTION! 2015-06-04 10:55:26.248:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@4f83df68{/test,file:///tmp/jetty-0.0.0.0-8080-test.war-_test-any-5238659347611323540.dir/webapp/,AVAILABLE}{/test.war} 2015-06-04 10:55:26.255:INFO:oejs.ServerConnector:main: Started ServerConnector@5a9c4ad9{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} 2015-06-04 10:55:26.259:INFO:oejus.SslContextFactory:main: x509={jetty.eclipse.org=jetty} wild={} alias=null for SslContextFactory@23941fb4(file:///opt/jetty-distribution-9.3.0.v20150601/demo-base/etc/keystore,file:///opt/jetty-distribution-9.3.0.v20150601/demo-base/etc/keystore) 2015-06-04 10:55:26.269:INFO:oejs.ServerConnector:main: Started ServerConnector@5d908d47{SSL,[ssl, http/1.1]}{0.0.0.0:8443} 2015-06-04 10:55:26.270:INFO:oejs.Server:main: Started @2417ms
如今能夠經過瀏覽器訪問 http://localhost:8080, 此時能夠看到一個Jetty的歡迎頁面,頁面上包含幾個簡單的例子,歡迎頁面以下
警告
示例的web應用程序不必定是絕對安全的,因此不該該部署在生產環境上。
你能夠經過如下命令查看示例應用的配置信息
> cd $JETTY_HOME/demo-base/ > java -jar $JETTY_HOME/start.jar --list-modules ... > java -jar %JETTY_HOME/start.jar --list-config ...
--list-modules:此命令將返回當前服務全部可用的模塊,同時也會顯示本地的模塊,信息包括模塊實現的順序,依賴模塊以及相應的jar信息
> JETTY_BASE=/tmp/mybase > mkdir $JETTY_BASE > cd $JETTY_BASE > java -jar $JETTY_HOME/start.jar WARNING: Nothing to start, exiting ... Usage: java -jar start.jar [options] [properties] [configs] java -jar start.jar --help # for more information > java -jar $JETTY_HOME/start.jar --add-to-startd=http,deploy INFO: server initialised (transitively) in ${jetty.base}/start.d/server.ini INFO: http initialised in ${jetty.base}/start.d/http.ini INFO: security initialised (transitively) in ${jetty.base}/start.d/security.ini INFO: servlet initialised (transitively) in ${jetty.base}/start.d/servlet.ini INFO: webapp initialised (transitively) in ${jetty.base}/start.d/webapp.ini INFO: deploy initialised in ${jetty.base}/start.d/deploy.ini MKDIR: ${jetty.base}/webapps INFO: Base directory was modified > cp $JETTY_HOME/demo-base/webapps/async-rest.war webapps/ROOT.war > java -jar $JETTY_HOME/start.jar 2015-06-04 11:10:16.286:INFO::main: Logging initialized @274ms 2015-06-04 11:10:16.440:INFO:oejs.Server:main: jetty-9.3.0.v20150601 2015-06-04 11:10:16.460:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///tmp/mybase/webapps/] at interval 1 2015-06-04 11:10:16.581:WARN::main: async-rest webapp is deployed. DO NOT USE IN PRODUCTION! 2015-06-04 11:10:16.589:INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet 2015-06-04 11:10:16.628:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@1a407d53{/,[file:///tmp/jetty-0.0.0.0-8080-ROOT.war-_-any-4510228025526425427.dir/webapp/, jar:file:///tmp/jetty-0.0.0.0-8080-ROOT.war-_-any-4510228025526425427.dir/webapp/WEB-INF/lib/example-async-rest-jar-9.3.0.v20150601.jar!/META-INF/resources],AVAILABLE}{/ROOT.war} 2015-06-04 11:10:16.645:INFO:oejs.ServerConnector:main: Started ServerConnector@3abbfa04{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} 2015-06-04 11:10:16.646:INFO:oejs.Server:main: Started @634ms
以上命令是Linux下的命令,簡單解釋:建立一個JETTY_BASE環境變量,並建立指定的文件夾,在此文件夾下運行start.jar時提示沒有能夠啓動的東西,系統退出,此時輸入java -jar $JETTY_HOME/start.jar --add-to-startd=http,deploy命令爲當前基目錄添加標準文件及文件夾,而後java -jar $JETTY_HOME/start.jar運行便可運行成功。在Windows下操做以下:
> cd $JETTY_BASE > java -jar $JETTY_HOME/start.jar jetty.http.port=8081 ...
另外,能夠將要設置的端口屬性添加到start.ini或者start.d/http.ini文件中。默認狀況,在start.d/http.ini文件中定義的jetty.http.port屬性能夠被修改爲另外一個值。
提示
配置屬性信息經過以下方式得到
- 首先去start.d/http.ini文件中找jetty.http.port=8080配置信息,若找到配置端口即爲指定端口
- 根據模塊modules/http.mod文件找到指定配置默認爲etc/jetty-http.xml,在此配置文件中有jetty.http.port配置信息,若找到即爲此端口配置
- 若上面兩個都沒有,則隨機一個沒有使用的端口
> java -jar $JETTY_HOME/start.jar --add-to-startd=https,http2 [...] > java -jar $JETTY_HOME/start.jar [...] 2015-06-04 13:52:01.933:INFO:oejs.ServerConnector:main: Started ServerConnector@6f1fba17{SSL,[ssl, alpn, h2, http/1.1]}{0.0.0.0:8443} [...]
--add-to-startd:此命令在ini文件中設置有效的配置信息,使HTTPS和HTTP2支持SSL鏈接
> cd $JETTY_BASE
> java -jar $JETTY_HOME/start.jar jetty.ssl.port=8444
除了在命令行增長參數的方法外,還能夠在start.ini和start.d/*.ini文件中進行配置,因此若是用戶使用--add-to-startd命令來使HTTPS生效,一樣也能夠在start.d/https.ini文件中進行修改。
> java -jar $JETTY_HOME/start.jar --help
提示
在Jetty9,只有Jetty基路徑下的配置文件被編輯,屬性纔會被修改
Note
常見典型的模塊配置信息通長不多被改動,*.mod文件一般位於$JETTY_HOME/modules/文件夾下,可是額外增長的或者編輯過的一般放在 $JETTY_BASE/module下,若是一個模塊須要被修改,最好的作法是在修改前從$JETTY_HOME/modules/拷貝*.mod到 $JETTY_BASE/modules/
XML files:
xml文件通常用與IoC以及spring使用,用在命令行或者模塊定義中。xml文件裏面的配置將被注入到描述服務的一個對象裏。一般改變屬性的方法是改變對應的ini文件。xml文件一般放在$JETTY_HOME/etc/下,可是新增的或者被編輯的xml應該被放在 $JETTY_BASE/etc/下,若是xml配置文件有修改的必要,最好的作法是在修改前將xml文件從$JETTY_HOME/etc拷貝到$JETTY_BASE/etc/ 。Note
一般web應用的web.xml文件應該在WEB-INF/web.xml位置被發現,Jetty還支持多個web.xml,能夠在 WEB-INF/web.xml文件加載前或者加載後加載(使用方法見test.xml)
// // ======================================================================== // Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. // ------------------------------------------------------------------------ // All rights reserved. This program and the accompanying materials // are made available under the terms of the Eclipse Public License v1.0 // and Apache License v2.0 which accompanies this distribution. // // The Eclipse Public License is available at // http://www.eclipse.org/legal/epl-v10.html // // The Apache License v2.0 is available at // http://www.opensource.org/licenses/apache2.0.php // // You may elect to redistribute this code under either of these licenses. // ======================================================================== // package org.eclipse.jetty.embedded; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.servlet.ServletContextHandler; public class ExampleServer { public static void main( String[] args ) throws Exception { Server server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setPort(8080); server.setConnectors(new Connector[] { connector }); ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); context.addServlet(HelloServlet.class, "/hello"); context.addServlet(AsyncEchoServlet.class, "/echo/*"); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[] { context, new DefaultHandler() }); server.setHandler(handlers); server.start(); server.join(); } }
<?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> <Configure id="ExampleServer" class="org.eclipse.jetty.server.Server"> <Set name="connectors"> <Array type="org.eclipse.jetty.server.Connector"> <Item> <New class="org.eclipse.jetty.server.ServerConnector"> <Arg><Ref refid="ExampleServer"/></Arg> <Set name="port">8080</Set> </New> </Item> </Array> </Set> <New id="context" class="org.eclipse.jetty.servlet.ServletContextHandler"> <Set name="contextPath">/hello</Set> <Call name="addServlet"> <Arg>org.eclipse.jetty.embedded.HelloServlet</Arg> <Arg>/</Arg> </Call> </New> <Set name="handler"> <New class="org.eclipse.jetty.server.handler.HandlerCollection"> <Set name="handlers"> <Array type="org.eclipse.jetty.server.Handler"> <Item> <Ref refid="context" /> </Item> <Item> <New class="org.eclipse.jetty.server.handler.DefaultHandler" /> </Item> </Array> </Set> </New> </Set> </Configure>
Note
虛擬主機不能配置鏈接,用戶應該經過虛擬主機的context來實現它們的相應。
Note
Jetty9同時支持鏈接協議(HTTP,HTTPS,AJP,SPDY)和天然鏈接(NIO或者BIO),Jetty9之後只有一個主要的鏈接器ServerConnector
Note
servlet規範定一個web應用。在Jetty規範中一個標準的web項目必須有一個標準的WEB-INF/web.xml文件,用來配置classpath,資源,session處理,登陸,以及servlet,jsp,以及靜態資源。標準的web應用須要不多的額外的配置文件。
// // ======================================================================== // Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. // ------------------------------------------------------------------------ // All rights reserved. This program and the accompanying materials // are made available under the terms of the Eclipse Public License v1.0 // and Apache License v2.0 which accompanies this distribution. // // The Eclipse Public License is available at // http://www.eclipse.org/legal/epl-v10.html // // The Apache License v2.0 is available at // http://www.opensource.org/licenses/apache2.0.php // // You may elect to redistribute this code under either of these licenses. // ======================================================================== // package org.eclipse.jetty.embedded; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandler; public class OneContext { public static void main( String[] args ) throws Exception { Server server = new Server( 8080 ); // Add a single handler on context "/hello" ContextHandler context = new ContextHandler(); context.setContextPath( "/hello" ); context.setHandler( new HelloHandler() ); // Can be accessed using http://localhost:8080/hello server.setHandler( context ); // Start the server server.start(); server.join(); } }
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"> <!-- Configure a custom context for serving javadoc as static resources --> <Configure class="org.eclipse.jetty.server.handler.ContextHandler"> <Set name="contextPath">/javadoc</Set> <Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/javadoc/</Set> <Set name="handler"> <New class="org.eclipse.jetty.server.handler.ResourceHandler"> <Set name="welcomeFiles"> <Array type="String"> <Item>index.html</Item> </Array> </Set> <Set name="cacheControl">max-age=3600,public</Set> </New> </Set> </Configure>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"> <Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="contextPath">/contextpath</Set> </Configure>
還有一種作法是,不用增長配置文件,在war文件同目錄,建一個同名的xml文件,內容以下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"> <Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test.war</Set> <Set name="contextPath">/test</Set> </Configure>
配置例子能夠參照$JETTY_HOME/webapps/test.xml
... <login-config> <auth-method>BASIC</auth-method> <realm-name>Test Realm</realm-name> </login-config> ...
這個例子使用名爲Test Realm.的驗證,可是沒有說明其是怎麼實現的,在Jetty中有幾種實現方式,其中一種是HashLoginService能夠讀取登陸用戶,並在配置文件中查找,爲了配置HashLoginService用來匹配Test Realm,能夠配置$JETTY_BASE/etc/test-realm.xml文件,而且該文件必須在start.ini或者start.d/server.ini中設置。
<?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-" "http://www.eclipse.org/jetty/configure_9_3.dtd"> <Configure id="Server" class="org.eclipse.jetty.server.Server"> <!-- =========================================================== --> <!-- Configure Authentication Login Service --> <!-- 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)/webapps/test.xml for an --> <!-- example). --> <!-- =========================================================== --> <Call name="addBean"> <Arg> <New class="org.eclipse.jetty.security.HashLoginService"> <Set name="name">Test Realm</Set> <Set name="config"><Property name="jetty.demo.realm" default="etc/realm.properties"/></Set> <Set name="refreshInterval">0</Set> </New> </Arg> </Call> <Get class="org.eclipse.jetty.util.log.Log" name="rootLogger"> <Call name="warn"><Arg>demo test-realm is deployed. DO NOT USE IN PRODUCTION!</Arg></Call> </Get> </Configure>
經過建立和配置LoginService到web應用中,當部署應用時,會經過名字去尋找匹配的登陸Service。
以上是翻譯的第一部分,Jetty全部目錄信息見:http://www.cnblogs.com/yiwangzhibujian/p/5832294.html,後面幾個部分比較多可能會分幾篇進行翻譯,不少地方翻譯的時候都不明白是如何使用的,所以有可能翻譯不到位,估計等我所有看完後纔會理解,那時候我會根據本身的理解寫一點新手教程。