如今咱们已经有能够能够运行的项目了,让咱们队这个项目进行一些测试吧。html
你须要运行下面的一些命令行:java
|
这个命令将会对项目进行编译后运行单元测试。github
你应该会看到和下面相似的输出表示项目编译成功了:浏览器
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.742 s [INFO] Finished at: 2018-03-27T15:05:50-04:00 [INFO] Final Memory: 17M/205M [INFO] ------------------------------------------------------------------------
上面的输出表示的是项目已经被编译测试经过了。
咱们能够开始使用独立启动方式启动项目了,但愿直接启动项目,须要运行下面的 mvn 项目启动命令:
|
这时候,项目应该已经正常启动了,很快你应该能够在控制台上看到下面的输出:app
Mar 27, 2018 3:10:28 PM org.glassfish.grizzly.http.server.NetworkListener start INFO: Started listener bound to [localhost:8080] Mar 27, 2018 3:10:28 PM org.glassfish.grizzly.http.server.HttpServer start INFO: [HttpServer] Started. Jersey app started with WADL available at http://localhost:8080/myapp/application.wadl Hit enter to stop it...
项目这个时候已经运行了,有关项目的 WADL 描述文件能够经过 URL 访问到。http://localhost:8080/myapp/application.wadl
你能够考虑在你的控制台中经过命令中 curl http://localhost:8080/myapp/application.wadl 访问这个项目的描述文件,你也能够直接将这个连接拷贝粘贴到浏览器中直接进行查看。
若是一切正常的话,你应该能够看到你部署的 RESTful 应用程序的的 WADL 格式的 XML 文档。但愿查看更多有关 WADL 的内容,请查看章节 Chapter 17, WADL Support。curl
部署成功后最后一件能够尝试的事情就是与部署的 /myresource 资源进行数据交互。单元测试
你能够考虑直接把 http://localhost:8080/myapp/myresource 连接复制粘贴到浏览器中,你也能够经过 curl 执行命令。测试
有关 curl 执行命令的结果以下:
$ curl http://localhost:8080/myapp/myresource Got it!
你能够看到,当你执行上面的命令后,控制台输出了 Got it!消息,这个消息是服务器发送给咱们的资源。
咱们也能够经过参数 -i 让 curl 提供更多的信息给咱们来让咱们了解有关消息发送响应的相关信息。
curl -i http://localhost:8080/myapp/myresource HTTP/1.1 200 OK Content-Type: text/plain Date: Sun, 26 May 2013 18:27:19 GMT Content-Length: 7 Got it!
注意到Content-Type: text/plain
是在 MyResource 类中用@Produces
注解的。
若是想看到更多返回信息,或者想了解 curl 客户端和运行的 Grizzly I/O 容器的交互,能够变换不一样的 curl 命令参数。例以下面的例子能够让 curl 客户端输出更多有关于服务器通讯和交互的相关信息:
$ curl -v http://localhost:8080/myapp/myresource * About to connect() to localhost port 8080 (#0) * Trying ::1... * Connection refused * Trying 127.0.0.1... * connected * Connected to localhost (127.0.0.1) port 8080 (#0) > GET /myapp/myresource HTTP/1.1 > User-Agent: curl/7.25.0 (x86_64-apple-darwin11.3.0) libcurl/7.25.0 OpenSSL/1.0.1e zlib/1.2.7 libidn/1.22 > Host: localhost:8080 > Accept: */* > < HTTP/1.1 200 OK < Content-Type: text/plain < Date: Sun, 26 May 2013 18:29:18 GMT < Content-Length: 7 < * Connection #0 to host localhost left intact Got it!* Closing connection #0