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

使用 Apache Wink、Eclipse 和 Maven 开发 RESTful Web 服务(2)
通过 Eclipse 获取 Apache Wink在这个小节中,您将使用 Eclipse 以及 Maven Integration for Eclipse(称为 m2eclipse)和 Subclipse 插件来安装 Apache Wink。(M2eclipse 提供从 Eclipse 对 Maven 的访问;Subclipse 提供对 Subversion 资源库的访问。)您还可以将 Eclipse 用作一个平台,从这个平台构建并运行 Web 服务。
先决条件在获取 Apache Wink 之前,要先下载并安装以下软件包(参见 获取下载 URLs):
- Java Software Development Kit (JDK) version 6。设置 JAVA_HOME 环境变量并添加到路径 %JAVA_HOME%\bin(在 Windows® 中)或 $JAVA_HOME/bin(在 Linux® 中)。
- Apache Tomcat version 6.0。设置 CATALINA_HOME 环境变量以指向安装目录。
- Eclipse IDE for Java™ Platform, Enterprise Edition (Java EE) developers。本文撰写之时的当前版本为 Eclipse Galileo。
安装 Subclipse要使用 Eclipse 管理具有 Maven 感知的项目,要安装 Eclipse 插件 Subclipse 和 m2eclipse。要安装 Subclipse 插件,执行以下步骤:
- 启动 Eclipse。
- 单击菜单栏中的 Help,然后选择 Install new software。
- 在 Available Software 窗口中,单击 Add。
- 在 Add Site 窗口中,输入:
然后单击 OK。
- 在 Available Software 窗口中,选择 Subclipse 下的 Subclipse (Required) 和 SVNKit Client Adapter (Not required) 复选框(如 图 1 所示),然后单击 Next。 图 1. 安装 Subclipse 插件
 - 在 Install Details 窗口中,单击 Next。
- 在 Review Licenses 窗口中,检查许可,接受许可协议条款,然后单击 Finish。
- 单击 Yes 重新启动 Eclipse。
安装 m2eclipsem2eclipse 插件的安装步骤与安装 Subclipse 插件类似,但有以下几点例外:
- 在 Add Site 窗口中输入:
然后单击 OK。
- 在 Available Software 窗口中,选择 Maven Integration for Eclipse (Required) 和 Maven SCM handler for Subclipse (Optional) 复选框(如 图 2 所示),然后单击 Next。 图 2. 安装 m2eclipse 插件
 获取 Apache Wink现在,您可以使用 Eclipse 从资源库检查 Apache Wink 示例,将必要的 Java 归档(JAR)文件(包括 Apache Wink JAR 文件)下载到一个本地资源库,构建并运行 Apache Wink HelloWorld 示例。为此,执行以下步骤:
- 在 Eclipse 中,选择 File > Import 启动 Import Wizard。
- 在 Select 向导页面的 Select and import source 文本框中输入 maven。
- 在 Maven 下,选择 Materialize Maven Projects 并单击 Next。
- 在 Select Maven artifacts 向导页面上单击 Add。
- 在 Add Dependency 页面上的 Enter groupId, artifactId 文本框中输入 org.apache.wink.example。
注意: Artifact(工件) 是一个用于 Maven 的术语,指的是设置了版本并存储在资源库中的软件包的层级结构。 - 在 Search Results 区域中,选择 org.apache.wink.example apps(如 图 3 所示)并单击 OK。 图 3. org.apache.wink.example 组中的应用程序工件
 - 在 Select Maven artifacts 向导页面上,单击 Next,然后单击 Finish。
- 在 Maven Projects 向导页面上,只选择 /pom.xml 复选框,然后单击 Finish。
Maven 处理一个工件的所有依赖项的方式是从远程资源库下载它们并构建一个本地资源库。Maven 的优势之一是能够处理临时依赖项;因此,在 Maven Project Object Model (POM) 文件中,只需声明工件的传递依赖项(transitive dependencies),Maven 将为您处理高阶依赖项(higher-order dependencies)。
步骤 8 完成后,将创建一个 Eclipse 项目,它包含 Apache Wink 示例的 apps 模块中的代码。在 Eclipse 的 Project Explorer 中浏览项目文件。 |
|
|
|
|
|