当前位置:   article > 正文

Eclipse内置jetty运行web项目的配置_org.eclipse.jetty webapp 本地运行

org.eclipse.jetty webapp 本地运行

一、加入maven依赖

 

  1. <eclipse.jetty.version>7.6.3.v20120416</eclipse.jetty.version>
  2. <dependency>
  3. <groupId>org.eclipse.jetty.aggregate</groupId>
  4. <artifactId>jetty-webapp</artifactId>
  5. <version>${eclipse.jetty.version}</version>
  6. <scope>provided</scope>
  7. </dependency>
  8. <dependency>
  9. <groupId>org.eclipse.jetty</groupId>
  10. <artifactId>jetty-server</artifactId>
  11. <version>${eclipse.jetty.version}</version>
  12. <scope>provided</scope>
  13. </dependency>
  1. <!--支持jsp的访问-->
  2. <dependency>
  3. <groupId>org.eclipse.jetty</groupId>
  4. <artifactId>jetty-jsp-2.1</artifactId>
  5. <version>7.2.2.v20101205</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.mortbay.jetty</groupId>
  9. <artifactId>jsp-2.1-glassfish</artifactId>
  10. <version>2.1.v20100127</version>
  11. </dependency>

 

 

 

 

 

二、webdefaults.xml下文件加入webapp目录,webdefaults.xml内容如下

 

  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!-- ===================================================================== -->
  3. <!-- This file contains the default descriptor for web applications. -->
  4. <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  5. <!-- The intent of this descriptor is to include jetty specific or common -->
  6. <!-- configuration for all webapps. If a context has a webdefault.xml -->
  7. <!-- descriptor, it is applied before the contexts own web.xml file -->
  8. <!-- -->
  9. <!-- A context may be assigned a default descriptor by: -->
  10. <!-- + Calling WebApplicationContext.setDefaultsDescriptor -->
  11. <!-- + Passed an arg to addWebApplications -->
  12. <!-- -->
  13. <!-- This file is used both as the resource within the jetty.jar (which is -->
  14. <!-- used as the default if no explicit defaults descriptor is set) and it -->
  15. <!-- is copied to the etc directory of the Jetty distro and explicitly -->
  16. <!-- by the jetty.xml file. -->
  17. <!-- -->
  18. <!-- ===================================================================== -->
  19. <web-app
  20. xmlns="http://java.sun.com/xml/ns/javaee"
  21. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  22. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  23. metadata-complete="true"
  24. version="2.5"
  25. >
  26. <description>
  27. Default web.xml file.
  28. This file is applied to a Web application before it's own WEB_INF/web.xml file
  29. </description>
  30. <!-- ==================================================================== -->
  31. <!-- Context params to control Session Cookies -->
  32. <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  33. <!--
  34. UNCOMMENT TO ACTIVATE <context-param> <param-name>org.eclipse.jetty.servlet.SessionDomain</param-name> <param-value>127.0.0.1</param-value> </context-param> <context-param>
  35. <param-name>org.eclipse.jetty.servlet.SessionPath</param-name> <param-value>/</param-value> </context-param> <context-param> <param-name>org.eclipse.jetty.servlet.MaxAge</param-name>
  36. <param-value>-1</param-value> </context-param>
  37. -->
  38. <!-- ==================================================================== -->
  39. <!-- The default servlet. -->
  40. <!-- This servlet, normally mapped to /, provides the handling for static -->
  41. <!-- content, OPTIONS and TRACE methods for the context. -->
  42. <!-- The following initParameters are supported: -->
  43. <!-- -->
  44. <!-- aliases If true, aliases like symlinks are allowed. Note -->
  45. <!-- that security constraints might be bypassed by -->
  46. <!-- aliases static content. -->
  47. <!-- -->
  48. <!-- acceptRanges If true, range requests and responses are -->
  49. <!-- supported -->
  50. <!-- -->
  51. <!-- dirAllowed If true, directory listings are returned if no -->
  52. <!-- welcome file is found. Else 403 Forbidden. -->
  53. <!-- -->
  54. <!-- welcomeServlets If true, attempt to dispatch to welcome files -->
  55. <!-- that are servlets, if no matching static -->
  56. <!-- resources can be found. -->
  57. <!-- -->
  58. <!-- redirectWelcome If true, redirect welcome file requests -->
  59. <!-- else use request dispatcher forwards -->
  60. <!-- -->
  61. <!-- gzip If set to true, then static content will be served-->
  62. <!-- as gzip content encoded if a matching resource is -->
  63. <!-- found ending with ".gz" -->
  64. <!-- -->
  65. <!-- resoureBase Can be set to replace the context resource base -->
  66. <!-- -->
  67. <!-- relativeResourceBase -->
  68. <!-- Set with a pathname relative to the base of the -->
  69. <!-- servlet context root. Useful for only serving -->
  70. <!-- static content from only specific subdirectories. -->
  71. <!-- -->
  72. <!-- useFileMappedBuffer -->
  73. <!-- If set to true (the default), a memory mapped -->
  74. <!-- file buffer will be used to serve static content -->
  75. <!-- when using an NIO connector. Setting this value -->
  76. <!-- to false means that a direct buffer will be used -->
  77. <!-- instead. If you are having trouble with Windows -->
  78. <!-- file locking, set this to false. -->
  79. <!-- -->
  80. <!-- cacheControl If set, all static content will have this value -->
  81. <!-- set as the cache-control header. -->
  82. <!-- -->
  83. <!-- maxCacheSize Maximum size of the static resource cache -->
  84. <!-- -->
  85. <!-- maxCachedFileSize Maximum size of any single file in the cache -->
  86. <!-- -->
  87. <!-- maxCachedFiles Maximum number of files in the cache -->
  88. <!-- -->
  89. <!-- cacheType "nio", "bio" or "both" to determine the type(s) -->
  90. <!-- of resource cache. A bio cached buffer may be used-->
  91. <!-- by nio but is not as efficient as a nio buffer. -->
  92. <!-- An nio cached buffer may not be used by bio. -->
  93. <!-- -->
  94. <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  95. <servlet>
  96. <servlet-name>default</servlet-name>
  97. <servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
  98. <init-param>
  99. <param-name>aliases</param-name>
  100. <param-value>false</param-value>
  101. </init-param>
  102. <init-param>
  103. <param-name>acceptRanges</param-name>
  104. <param-value>true</param-value>
  105. </init-param>
  106. <init-param>
  107. <param-name>dirAllowed</param-name>
  108. <param-value>true</param-value>
  109. </init-param>
  110. <init-param>
  111. <param-name>welcomeServlets</param-name>
  112. <param-value>false</param-value>
  113. </init-param>
  114. <init-param>
  115. <param-name>redirectWelcome</param-name>
  116. <param-value>false</param-value>
  117. </init-param>
  118. <init-param>
  119. <param-name>maxCacheSize</param-name>
  120. <param-value>256000000</param-value>
  121. </init-param>
  122. <init-param>
  123. <param-name>maxCachedFileSize</param-name>
  124. <param-value>10000000</param-value>
  125. </init-param>
  126. <init-param>
  127. <param-name>maxCachedFiles</param-name>
  128. <param-value>1000</param-value>
  129. </init-param>
  130. <init-param>
  131. <param-name>cacheType</param-name>
  132. <param-value>both</param-value>
  133. </init-param>
  134. <init-param>
  135. <param-name>gzip</param-name>
  136. <param-value>true</param-value>
  137. </init-param>
  138. <init-param>
  139. <param-name>useFileMappedBuffer</param-name>
  140. <param-value>false</param-value>
  141. </init-param>
  142. <!--
  143. <init-param>
  144. <param-name>cacheControl</param-name>
  145. <param-value>max-age=3600,public</param-value>
  146. </init-param>
  147. -->
  148. <load-on-startup>0</load-on-startup>
  149. </servlet>
  150. <servlet-mapping>
  151. <servlet-name>default</servlet-name>
  152. <url-pattern>/</url-pattern>
  153. </servlet-mapping>
  154. <!-- ==================================================================== -->
  155. <!-- JSP Servlet -->
  156. <!-- This is the jasper JSP servlet from the jakarta project -->
  157. <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  158. <!-- The JSP page compiler and execution servlet, which is the mechanism -->
  159. <!-- used by Glassfish to support JSP pages. Traditionally, this servlet -->
  160. <!-- is mapped to URL patterh "*.jsp". This servlet supports the -->
  161. <!-- following initialization parameters (default values are in square -->
  162. <!-- brackets): -->
  163. <!-- -->
  164. <!-- checkInterval If development is false and reloading is true, -->
  165. <!-- background compiles are enabled. checkInterval -->
  166. <!-- is the time in seconds between checks to see -->
  167. <!-- if a JSP page needs to be recompiled. [300] -->
  168. <!-- -->
  169. <!-- compiler Which compiler Ant should use to compile JSP -->
  170. <!-- pages. See the Ant documenation for more -->
  171. <!-- information. [javac] -->
  172. <!-- -->
  173. <!-- classdebuginfo Should the class file be compiled with -->
  174. <!-- debugging information? [true] -->
  175. <!-- -->
  176. <!-- classpath What class path should I use while compiling -->
  177. <!-- generated servlets? [Created dynamically -->
  178. <!-- based on the current web application] -->
  179. <!-- Set to ? to make the container explicitly set -->
  180. <!-- this parameter. -->
  181. <!-- -->
  182. <!-- development Is Jasper used in development mode (will check -->
  183. <!-- for JSP modification on every access)? [true] -->
  184. <!-- -->
  185. <!-- enablePooling Determines whether tag handler pooling is -->
  186. <!-- enabled [true] -->
  187. <!-- -->
  188. <!-- fork Tell Ant to fork compiles of JSP pages so that -->
  189. <!-- a separate JVM is used for JSP page compiles -->
  190. <!-- from the one Tomcat is running in. [true] -->
  191. <!-- -->
  192. <!-- ieClassId The class-id value to be sent to Internet -->
  193. <!-- Explorer when using <jsp:plugin> tags. -->
  194. <!-- [clsid:8AD9C840-044E-11D1-B3E9-00805F499D93] -->
  195. <!-- -->
  196. <!-- javaEncoding Java file encoding to use for generating java -->
  197. <!-- source files. [UTF-8] -->
  198. <!-- -->
  199. <!-- keepgenerated Should we keep the generated Java source code -->
  200. <!-- for each page instead of deleting it? [true] -->
  201. <!-- -->
  202. <!-- logVerbosityLevel The level of detailed messages to be produced -->
  203. <!-- by this servlet. Increasing levels cause the -->
  204. <!-- generation of more messages. Valid values are -->
  205. <!-- FATAL, ERROR, WARNING, INFORMATION, and DEBUG. -->
  206. <!-- [WARNING] -->
  207. <!-- -->
  208. <!-- mappedfile Should we generate static content with one -->
  209. <!-- print statement per input line, to ease -->
  210. <!-- debugging? [false] -->
  211. <!-- -->
  212. <!-- -->
  213. <!-- reloading Should Jasper check for modified JSPs? [true] -->
  214. <!-- -->
  215. <!-- suppressSmap Should the generation of SMAP info for JSR45 -->
  216. <!-- debugging be suppressed? [false] -->
  217. <!-- -->
  218. <!-- dumpSmap Should the SMAP info for JSR45 debugging be -->
  219. <!-- dumped to a file? [false] -->
  220. <!-- False if suppressSmap is true -->
  221. <!-- -->
  222. <!-- scratchdir What scratch directory should we use when -->
  223. <!-- compiling JSP pages? [default work directory -->
  224. <!-- for the current web application] -->
  225. <!-- -->
  226. <!-- tagpoolMaxSize The maximum tag handler pool size [5] -->
  227. <!-- -->
  228. <!-- xpoweredBy Determines whether X-Powered-By response -->
  229. <!-- header is added by generated servlet [false] -->
  230. <!-- -->
  231. <!-- If you wish to use Jikes to compile JSP pages: -->
  232. <!-- Set the init parameter "compiler" to "jikes". Define -->
  233. <!-- the property "-Dbuild.compiler.emacs=true" when starting Jetty -->
  234. <!-- to cause Jikes to emit error messages in a format compatible with -->
  235. <!-- Jasper. -->
  236. <!-- If you get an error reporting that jikes can't use UTF-8 encoding, -->
  237. <!-- try setting the init parameter "javaEncoding" to "ISO-8859-1". -->
  238. <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  239. <servlet
  240. id="jsp"
  241. >
  242. <servlet-name>jsp</servlet-name>
  243. <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
  244. <init-param>
  245. <param-name>logVerbosityLevel</param-name>
  246. <param-value>DEBUG</param-value>
  247. </init-param>
  248. <init-param>
  249. <param-name>fork</param-name>
  250. <param-value>false</param-value>
  251. </init-param>
  252. <init-param>
  253. <param-name>xpoweredBy</param-name>
  254. <param-value>false</param-value>
  255. </init-param>
  256. <!--
  257. <init-param>
  258. <param-name>classpath</param-name>
  259. <param-value>?</param-value>
  260. </init-param>
  261. -->
  262. <load-on-startup>0</load-on-startup>
  263. </servlet>
  264. <servlet-mapping>
  265. <servlet-name>jsp</servlet-name>
  266. <url-pattern>*.jsp</url-pattern>
  267. <url-pattern>*.jspf</url-pattern>
  268. <url-pattern>*.jspx</url-pattern>
  269. <url-pattern>*.xsp</url-pattern>
  270. <url-pattern>*.JSP</url-pattern>
  271. <url-pattern>*.JSPF</url-pattern>
  272. <url-pattern>*.JSPX</url-pattern>
  273. <url-pattern>*.XSP</url-pattern>
  274. </servlet-mapping>
  275. <!-- ==================================================================== -->
  276. <!-- Dynamic Servlet Invoker. -->
  277. <!-- This servlet invokes anonymous servlets that have not been defined -->
  278. <!-- in the web.xml or by other means. The first element of the pathInfo -->
  279. <!-- of a request passed to the envoker is treated as a servlet name for -->
  280. <!-- an existing servlet, or as a class name of a new servlet. -->
  281. <!-- This servlet is normally mapped to /servlet/* -->
  282. <!-- This servlet support the following initParams: -->
  283. <!-- -->
  284. <!-- nonContextServlets If false, the invoker can only load -->
  285. <!-- servlets from the contexts classloader. -->
  286. <!-- This is false by default and setting this -->
  287. <!-- to true may have security implications. -->
  288. <!-- -->
  289. <!-- verbose If true, log dynamic loads -->
  290. <!-- -->
  291. <!-- * All other parameters are copied to the -->
  292. <!-- each dynamic servlet as init parameters -->
  293. <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  294. <!--
  295. Uncomment for dynamic invocation <servlet> <servlet-name>invoker</servlet-name> <servlet-class>org.eclipse.jetty.servlet.Invoker</servlet-class> <init-param> <param-name>verbose</param-name>
  296. <param-value>false</param-value> </init-param> <init-param> <param-name>nonContextServlets</param-name> <param-value>false</param-value> </init-param> <init-param>
  297. <param-name>dynamicParam</param-name> <param-value>anyValue</param-value> </init-param> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>invoker</servlet-name>
  298. <url-pattern>/servlet/*</url-pattern> </servlet-mapping>
  299. -->
  300. <!-- ==================================================================== -->
  301. <session-config>
  302. <session-timeout>30</session-timeout>
  303. </session-config>
  304. <!-- ==================================================================== -->
  305. <!-- Default MIME mappings -->
  306. <!-- The default MIME mappings are provided by the mime.properties -->
  307. <!-- resource in the org.eclipse.jetty.server.jar file. Additional or modified -->
  308. <!-- mappings may be specified here -->
  309. <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  310. <!-- UNCOMMENT TO ACTIVATE
  311. <mime-mapping>
  312. <extension>mysuffix</extension>
  313. <mime-type>mymime/type</mime-type>
  314. </mime-mapping>
  315. -->
  316. <!-- ==================================================================== -->
  317. <welcome-file-list>
  318. <welcome-file>index.html</welcome-file>
  319. <welcome-file>index.htm</welcome-file>
  320. <welcome-file>index.jsp</welcome-file>
  321. </welcome-file-list>
  322. <!-- ==================================================================== -->
  323. <locale-encoding-mapping-list>
  324. <locale-encoding-mapping>
  325. <locale>ar</locale>
  326. <encoding>ISO-8859-6</encoding>
  327. </locale-encoding-mapping>
  328. <locale-encoding-mapping>
  329. <locale>be</locale>
  330. <encoding>ISO-8859-5</encoding>
  331. </locale-encoding-mapping>
  332. <locale-encoding-mapping>
  333. <locale>bg</locale>
  334. <encoding>ISO-8859-5</encoding>
  335. </locale-encoding-mapping>
  336. <locale-encoding-mapping>
  337. <locale>ca</locale>
  338. <encoding>ISO-8859-1</encoding>
  339. </locale-encoding-mapping>
  340. <locale-encoding-mapping>
  341. <locale>cs</locale>
  342. <encoding>ISO-8859-2</encoding>
  343. </locale-encoding-mapping>
  344. <locale-encoding-mapping>
  345. <locale>da</locale>
  346. <encoding>ISO-8859-1</encoding>
  347. </locale-encoding-mapping>
  348. <locale-encoding-mapping>
  349. <locale>de</locale>
  350. <encoding>ISO-8859-1</encoding>
  351. </locale-encoding-mapping>
  352. <locale-encoding-mapping>
  353. <locale>el</locale>
  354. <encoding>ISO-8859-7</encoding>
  355. </locale-encoding-mapping>
  356. <locale-encoding-mapping>
  357. <locale>en</locale>
  358. <encoding>ISO-8859-1</encoding>
  359. </locale-encoding-mapping>
  360. <locale-encoding-mapping>
  361. <locale>es</locale>
  362. <encoding>ISO-8859-1</encoding>
  363. </locale-encoding-mapping>
  364. <locale-encoding-mapping>
  365. <locale>et</locale>
  366. <encoding>ISO-8859-1</encoding>
  367. </locale-encoding-mapping>
  368. <locale-encoding-mapping>
  369. <locale>fi</locale>
  370. <encoding>ISO-8859-1</encoding>
  371. </locale-encoding-mapping>
  372. <locale-encoding-mapping>
  373. <locale>fr</locale>
  374. <encoding>ISO-8859-1</encoding>
  375. </locale-encoding-mapping>
  376. <locale-encoding-mapping>
  377. <locale>hr</locale>
  378. <encoding>ISO-8859-2</encoding>
  379. </locale-encoding-mapping>
  380. <locale-encoding-mapping>
  381. <locale>hu</locale>
  382. <encoding>ISO-8859-2</encoding>
  383. </locale-encoding-mapping>
  384. <locale-encoding-mapping>
  385. <locale>is</locale>
  386. <encoding>ISO-8859-1</encoding>
  387. </locale-encoding-mapping>
  388. <locale-encoding-mapping>
  389. <locale>it</locale>
  390. <encoding>ISO-8859-1</encoding>
  391. </locale-encoding-mapping>
  392. <locale-encoding-mapping>
  393. <locale>iw</locale>
  394. <encoding>ISO-8859-8</encoding>
  395. </locale-encoding-mapping>
  396. <locale-encoding-mapping>
  397. <locale>ja</locale>
  398. <encoding>Shift_JIS</encoding>
  399. </locale-encoding-mapping>
  400. <locale-encoding-mapping>
  401. <locale>ko</locale>
  402. <encoding>EUC-KR</encoding>
  403. </locale-encoding-mapping>
  404. <locale-encoding-mapping>
  405. <locale>lt</locale>
  406. <encoding>ISO-8859-2</encoding>
  407. </locale-encoding-mapping>
  408. <locale-encoding-mapping>
  409. <locale>lv</locale>
  410. <encoding>ISO-8859-2</encoding>
  411. </locale-encoding-mapping>
  412. <locale-encoding-mapping>
  413. <locale>mk</locale>
  414. <encoding>ISO-8859-5</encoding>
  415. </locale-encoding-mapping>
  416. <locale-encoding-mapping>
  417. <locale>nl</locale>
  418. <encoding>ISO-8859-1</encoding>
  419. </locale-encoding-mapping>
  420. <locale-encoding-mapping>
  421. <locale>no</locale>
  422. <encoding>ISO-8859-1</encoding>
  423. </locale-encoding-mapping>
  424. <locale-encoding-mapping>
  425. <locale>pl</locale>
  426. <encoding>ISO-8859-2</encoding>
  427. </locale-encoding-mapping>
  428. <locale-encoding-mapping>
  429. <locale>pt</locale>
  430. <encoding>ISO-8859-1</encoding>
  431. </locale-encoding-mapping>
  432. <locale-encoding-mapping>
  433. <locale>ro</locale>
  434. <encoding>ISO-8859-2</encoding>
  435. </locale-encoding-mapping>
  436. <locale-encoding-mapping>
  437. <locale>ru</locale>
  438. <encoding>ISO-8859-5</encoding>
  439. </locale-encoding-mapping>
  440. <locale-encoding-mapping>
  441. <locale>sh</locale>
  442. <encoding>ISO-8859-5</encoding>
  443. </locale-encoding-mapping>
  444. <locale-encoding-mapping>
  445. <locale>sk</locale>
  446. <encoding>ISO-8859-2</encoding>
  447. </locale-encoding-mapping>
  448. <locale-encoding-mapping>
  449. <locale>sl</locale>
  450. <encoding>ISO-8859-2</encoding>
  451. </locale-encoding-mapping>
  452. <locale-encoding-mapping>
  453. <locale>sq</locale>
  454. <encoding>ISO-8859-2</encoding>
  455. </locale-encoding-mapping>
  456. <locale-encoding-mapping>
  457. <locale>sr</locale>
  458. <encoding>ISO-8859-5</encoding>
  459. </locale-encoding-mapping>
  460. <locale-encoding-mapping>
  461. <locale>sv</locale>
  462. <encoding>ISO-8859-1</encoding>
  463. </locale-encoding-mapping>
  464. <locale-encoding-mapping>
  465. <locale>tr</locale>
  466. <encoding>ISO-8859-9</encoding>
  467. </locale-encoding-mapping>
  468. <locale-encoding-mapping>
  469. <locale>uk</locale>
  470. <encoding>ISO-8859-5</encoding>
  471. </locale-encoding-mapping>
  472. <locale-encoding-mapping>
  473. <locale>zh</locale>
  474. <encoding>GB2312</encoding>
  475. </locale-encoding-mapping>
  476. <locale-encoding-mapping>
  477. <locale>zh_TW</locale>
  478. <encoding>Big5</encoding>
  479. </locale-encoding-mapping>
  480. </locale-encoding-mapping-list>
  481. <security-constraint>
  482. <web-resource-collection>
  483. <web-resource-name>Disable TRACE</web-resource-name>
  484. <url-pattern>/</url-pattern>
  485. <http-method>TRACE</http-method>
  486. </web-resource-collection>
  487. <auth-constraint/>
  488. </security-constraint>
  489. </web-app>

 

三、新建一个执行类

 

 

  1. import java.io.IOException;
  2. import org.eclipse.jetty.server.Connector;
  3. import org.eclipse.jetty.server.Handler;
  4. import org.eclipse.jetty.server.Server;
  5. import org.eclipse.jetty.server.handler.ContextHandler;
  6. import org.eclipse.jetty.server.handler.HandlerList;
  7. import org.eclipse.jetty.server.handler.ResourceHandler;
  8. import org.eclipse.jetty.server.nio.SelectChannelConnector;
  9. import org.eclipse.jetty.util.thread.QueuedThreadPool;
  10. import org.eclipse.jetty.webapp.WebAppContext;
  11. public class ShiroMain {
  12. /**
  13. * @param args
  14. */
  15. public static void main(String[] args) throws IOException{
  16. int port = 8099;
  17. if (args.length > 0)
  18. {
  19. try
  20. {
  21. port = new Integer(args[0]);
  22. }
  23. catch (NumberFormatException e)
  24. {
  25. System.err.println("Invalid port '" + args[0] + "'. Port must be a number.");
  26. System.exit(1);
  27. }
  28. }
  29. System.setProperty("profiles.active", "development");
  30. Server server = new Server();
  31. //System.setProperty("org.eclipse.jetty.util.URI.charset","ISO-8859-1");
  32. QueuedThreadPool threadPool = new QueuedThreadPool();
  33. threadPool.setMaxThreads(100);
  34. server.setThreadPool(threadPool);
  35. Connector connector = new SelectChannelConnector();
  36. connector.setPort(port);
  37. server.setConnectors(new Connector[] { connector });
  38. WebAppContext context = new WebAppContext();
  39. context.setContextPath("/");
  40. context.setResourceBase("src/main/webapp");
  41. context.setDefaultsDescriptor("src/main/webapp/webdefaults.xml");
  42. //static
  43. context.setMaxFormContentSize(-1);
  44. ResourceHandler staticResourceHandler = new ResourceHandler();
  45. staticResourceHandler.setResourceBase("/home/www/upload");
  46. staticResourceHandler.setDirectoriesListed(true);
  47. ContextHandler staticContextHandler = new ContextHandler();
  48. staticContextHandler.setContextPath("/upload");
  49. staticContextHandler.setHandler(staticResourceHandler);
  50. HandlerList handlers = new HandlerList();
  51. handlers.setHandlers(new Handler[] { staticContextHandler, context });
  52. server.setHandler(handlers);
  53. try {
  54. server.start();
  55. server.join();
  56. } catch (Exception e) {
  57. e.printStackTrace();
  58. }
  59. }
  60. }

 

 
四、可能出现的问题

 

启动jetty后,打开JSP页面报错:

Unable to compile class for JSP

解决方法:

jdk1.8中的tools.jar加入jdk1.8\jre\lib\ext目录

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/124435
推荐阅读
相关标签
  

闽ICP备14008679号