使用 Apache Wink、Eclipse 和 Maven 开发 RESTful Web 服务(4)
 
- UID
- 1066743
|

使用 Apache Wink、Eclipse 和 Maven 开发 RESTful Web 服务(4)
现在可以将这个服务部署到 Tomcat 了,方法是执行 Tomcat 插件的 redeploy 目标。(一个 Maven 目标(goal) 被自身执行,这与生命周期阶段不同,后者的执行由生命周期中的此前阶段自动推进。)要执行 redeploy 目标,执行以下步骤:
- 在 Tomcat 配置文件 conf/tomcat-users.xml(位于 CATALINA_HOME 下)中插入身份验证信息(如 所示),但要使用一个密码,而不是 admin。 图 7. Tomcat 身份验证配置
 - 通过运行以下命令启动 Tomcat:
1
2
| In Windows: %CATALINA_HOME%\bin\catalina.bat start
In Linux: $CATALINA_HOME/bin/catalina.sh start
|
- 执行 maven tomcat:redeploy,这条命令使用 Tomcat manager 应用程序将 HelloWorld.war 部署到 Tomcat。为此,执行以下步骤:
- 在 Project Explorer 视图中,右键单击 HelloWorld,然后单击 Run As > Run configurations。
- 在 Create, manage, and run configurations 窗口中,选择 Maven Build > New_configuration,然后单击 Main 选项卡(参见 )。 图 8. 运行 tomcat:redeploy 目标
 - 单击 Browse workspace,然后选择 apps > HelloWorld,然后单击 OK。
- 在 Goals 文本框中,输入 tomcat:redeploy,然后单击 Run。 如果 redeploy 目标成功执行,Console 视图将显示消息 “Build successful”。
现在,您可以使用一个 HTTP 客户机(比如 Curl)调用 HelloWorld 服务,如 所示。
清单 3. 在 Curl 中调用 HelloWorld 服务1
2
3
4
5
6
7
8
9
| $ curl -X GET http://localhost:8080/HelloWorld/rest/world
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:ns2="http://a9.com/-/spec/opensearch/1.1/"
xmlns:ns3="http://www.w3.org/1999/xhtml">
<id>helloworld:1</id>
<updated>2010-01-06T13:26:43.924+01:00</updated>
<title type="text">Hello World!</title>
</entry>
|
|
|
|
|
|
|