自我介绍的网站设计怎么做,wordpress自定义类型的分类名称,做门户网站可以用的字体,欧美视频在线电影尽管很长一段时间以来我一直在使用Maven#xff0c;但直到最近我才使用过Jetty插件。 为了能够测试REST客户端#xff0c;我创建了一个Servlet#xff0c;向我显示了所有传入的参数和带有传入请求的标头。 为了在容器中运行servlet#xff0c;我决定尝试使用Maven Jetty插件… 尽管很长一段时间以来我一直在使用Maven但直到最近我才使用过Jetty插件。 为了能够测试REST客户端我创建了一个Servlet向我显示了所有传入的参数和带有传入请求的标头。 为了在容器中运行servlet我决定尝试使用Maven Jetty插件 。 所以首先我使用特定的Maven原型创建一个Web应用程序 mvn archetype:generate -DgroupIdnet.pascalalma -DartifactIdrest-service -Dversion1.0.0-SNAPSHOT -DarchetypeArtifactIdmaven-archetype-webapp 这将导致完整的项目和以下日志记录 [INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] maven-archetype-plugin:2.2:generate (default-cli) standalone-pom
[INFO]
[INFO] maven-archetype-plugin:2.2:generate (default-cli) standalone-pom
[INFO]
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) standalone-pom ---
[INFO] Generating project in Interactive mode
Downloading: http://artifactory.redstream.nl/repo/org/apache/maven/archetypes/maven-archetype-webapp/1.0/maven-archetype-webapp-1.0.jar
Downloaded: http://artifactory.redstream.nl/repo/org/apache/maven/archetypes/maven-archetype-webapp/1.0/maven-archetype-webapp-1.0.jar (4 KB at 5.2 KB/sec)
Downloading: http://artifactory.redstream.nl/repo/org/apache/maven/archetypes/maven-archetype-webapp/1.0/maven-archetype-webapp-1.0.pom
Downloaded: http://artifactory.redstream.nl/repo/org/apache/maven/archetypes/maven-archetype-webapp/1.0/maven-archetype-webapp-1.0.pom (533 B at 1.1 KB/sec)
[INFO] Using property: groupId net.pascalalma
[INFO] Using property: artifactId rest-service
[INFO] Using property: version 1.0.0-SNAPSHOT
[INFO] Using property: package net.pascalalma
Confirm properties configuration:
groupId: net.pascalalma
artifactId: rest-service
version: 1.0.0-SNAPSHOT
package: net.pascalalmaY: : Y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-webapp:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: net.pascalalma
[INFO] Parameter: packageName, Value: net.pascalalma
[INFO] Parameter: package, Value: net.pascalalma
[INFO] Parameter: artifactId, Value: rest-service
[INFO] Parameter: basedir, Value: /Users/pascal/projects
[INFO] Parameter: version, Value: 1.0.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: /Users/pascal/projects/rest-service
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.057s
[INFO] Finished at: Sun Feb 03 17:13:33 CET 2013
[INFO] Final Memory: 7M/81M
[INFO] ------------------------------------------------------------------------
MacBook-Air-van-Pascal:projects pascal$ 接下来我将servlet代码添加到项目中 package net.pascalalma.servlets;import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;/**** author pascal*/
public class TestRestServlet extends HttpServlet {public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException {PrintWriter out response.getWriter();out.println(GET method called);out.println(parameters:\n parameters(request));out.println(headers:\n headers(request));}public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException {PrintWriter out response.getWriter();out.println(POST method called);out.println(parameters: parameters(request));out.println(headers: headers(request));}public void doDelete(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException {PrintWriter out response.getWriter();out.println(Delete method called);}private String parameters(HttpServletRequest request) {StringBuilder builder new StringBuilder();for (Enumeration e request.getParameterNames(); e.hasMoreElements();) {String name (String) e.nextElement();builder.append(| name - request.getParameter(name)\n);}return builder.toString();}private String headers(HttpServletRequest request) {StringBuilder builder new StringBuilder();for (Enumeration e request.getHeaderNames(); e.hasMoreElements();) {String name (String) e.nextElement();builder.append(| name - request.getHeader(name)\n);}return builder.toString();}
} 并在“ web.xml”中配置servlet。 顺便说一下生成的“ web.xml”无法显示在我的Netbeans版本v7.2.1中。 我收到消息 Web应用程序版本不受支持。 将web.xml升级到2.4或更高版本或使用以前的NetBeans版本 为了解决这个问题我修改了web.xml使其从以下命名空间声明开始 web-app xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance
xmlnshttp://java.sun.com/xml/ns/javaee
xmlns:webhttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd
xsi:schemaLocationhttp://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd idWebApp_ID version2.5 接下来将servlet添加到修改后的“ web.xml”中 ?xml version1.0 encodingUTF-8?
...display-nameArchetype Created Web Application/display-nameservletservlet-nameTestRestServlet/servlet-nameservlet-classnet.pascalalma.servlets.TestRestServlet/servlet-class/servletservlet-mappingservlet-nameTestRestServlet/servlet-nameurl-pattern/TestRestServlet/url-pattern/servlet-mapping
... 现在一切准备就绪可以测试servlet。 正如我之前所说的我将为此使用Jetty插件。 要将插件添加到项目中只需将以下内容放入“ pom.xml”中 pluginsplugingroupIdorg.mortbay.jetty/groupIdartifactIdjetty-maven-plugin/artifactIdconfigurationscanIntervalSeconds10/scanIntervalSecondscontextPath//contextPathscanIntervalSeconds10/scanIntervalSecondsstopKeySTOP/stopKeystopPort8005/stopPortport8080/port/configuration/plugin
/plugins 现在我可以在终端中运行命令“ mvn jettyrun”以使容器运行servlet。 日志应该以以下内容结尾 ....
2013-02-19 09:54:53.044:INFO:oejs.AbstractConnector:Started SelectChannelConnector0.0.0.0:8080
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 10 seconds./code 现在如果您打开浏览器并转到该URLhttp// localhost8080 / TestRestServletbla true8217 ; 您将看到servlet的运行并输出到浏览器 GET method called
parameters:
|bla-trueheaders:
|DNT-1
|Host-localhost:8080
|Accept-text/html,application/xhtmlxml,application/xml;q0.9,*/*;q0.8
|Accept-Charset-ISO-8859-1,utf-8;q0.7,*;q0.3
|Accept-Language-en-US,en;q0.8
|User-Agent-Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17
|Connection-keep-alive
|Cache-Control-max-age0
|Accept-Encoding-gzip,deflate,sdch 注意事项如您所见在插件配置中为方便起见我添加了一些额外的参数。 因此容器将每隔10秒检查一次servlet中的更改因此我不必在每次更改servlet之后重新启动Jetty容器。 要停止容器您现在可以在另一个终端会话中输入命令mvn jettystop -DstopPort 8005 -DstopKey STOP。 顺便说一句请确保将插件命名为“ jetty-maven-plugin”而不是“ maven-jetty-plugin”因为那样您将使用该插件的旧版本而该插件不会使用配置参数是的非常令我感到困惑和沮丧。 参考在The Pragmatic Integrator博客上使用我们JCG合作伙伴 Pascal Alma的Maven Jetty插件 。 翻译自: https://www.javacodegeeks.com/2013/03/using-maven-jetty-plugin.html