Rapid Development 快速开发

    一般 Eclipse 都集成 Maven 的插件,如果没有,要想在 Eclipse 中使用 Maven,需要 安装 M2Eclipse 插件。有关 M2Eclipse 的安装可以参考http://www.eclipse.org/m2e/。安装完后就能导入 Maven 项目,使用 Maven 的命令行。

    4. Rapid Development 快速开发 - 图2

    放了方便运行项目,可以将 Servlet 容器嵌入进项目中。下面谈下几种 常见的 Servlet 容器的嵌入。

    设置插件

    项目启动成功,可以看到输出:

    在浏览器里访问 就能看到主页面了。

    4. Rapid Development 快速开发 - 图4

    嵌入 Jetty

    设置插件

    1. <plugin>
    2. <groupId>org.eclipse.jetty</groupId>
    3. <artifactId>jetty-maven-plugin</artifactId>
    4. <version>${jetty.version}</version>
    5. </plugin>

    执行

    项目启动成功,可以看到输出:

    1. [INFO] Scanning for projects...
    2. [INFO]
    3. [INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
    4. [INFO]
    5. [INFO] ------------------------------------------------------------------------
    6. [INFO] Building servlet-container 1.0-SNAPSHOT
    7. [INFO] ------------------------------------------------------------------------
    8. [INFO] >>> jetty-maven-plugin:9.2.9.v20150224:run (default-cli) @ servlet-container >>>
    9. [INFO]
    10. [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ servlet-container ---
    11. [INFO] skip non existing resourceDirectory D:\workspaceGithub\rest-in-action\samples\servlet-container\src\main\resources
    12. [INFO]
    13. [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ servlet-container ---
    14. [INFO] Nothing to compile - all classes are up to date
    15. [INFO]
    16. [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ servlet-container ---
    17. [INFO] Using 'UTF-8' encoding to copy filtered resources.
    18. [INFO] skip non existing resourceDirectory D:\workspaceGithub\rest-in-action\samples\servlet-container\src\test\resources
    19. [INFO]
    20. [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ servlet-container ---
    21. [INFO] No sources to compile
    22. [INFO]
    23. [INFO] <<< jetty-maven-plugin:9.2.9.v20150224:run (default-cli) @ servlet-container <<<
    24. [INFO]
    25. [INFO] --- jetty-maven-plugin:9.2.9.v20150224:run (default-cli) @ servlet-container ---
    26. [INFO] webAppSourceDirectory not set. Trying src\main\webapp
    27. [INFO] Reload Mechanic: automatic
    28. [INFO] Classes = D:\workspaceGithub\rest-in-action\samples\servlet-container\target\classes
    29. [INFO] Context path = /
    30. [INFO] Tmp directory = D:\workspaceGithub\rest-in-action\samples\servlet-container\target\tmp
    31. [INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
    32. [INFO] Web overrides = none
    33. [INFO] web.xml file = file:/D:/workspaceGithub/rest-in-action/samples/servlet-container/src/main/webapp/WEB-INF/web.xml
    34. [INFO] Webapp directory = D:\workspaceGithub\rest-in-action\samples\servlet-container\src\main\webapp
    35. 2015-03-02 15:06:54.713:INFO:oejs.Server:main: jetty-9.2.9.v20150224
    36. 2015-03-02 15:06:55.885:INFO:oejsh.ContextHandler:main: Started o.e.j.m.p.JettyWebAppContext@2863c{/,file:/D:/workspaceGithub/rest-in-action/samples/servlet-container/src/main/webapp/,AVAILABLE}{file:/D:/workspaceGithub/rest-in-action/samples/servlet-container/src/main/webapp/}
    37. 2015-03-02 15:06:55.886:WARN:oejsh.RequestLogHandler:main: !RequestLog
    38. [INFO] Started Jetty Server
    39. 2015-03-02 15:06:55.911:INFO:oejs.ServerConnector:main: Started ServerConnector@1dde93{HTTP/1.1}{0.0.0.0:8080}
    40. 2015-03-02 15:06:55.912:INFO:oejs.Server:main: Started @3022ms

    在浏览器里访问 就能看到主页面了。这里 Jetty 启动项目是默认是不显示项目名称的。

    4. Rapid Development 快速开发 - 图6