使用 WebSphere Developer Tools for Eclipse 在 Liberty 上创建一个 Hello World 应用程序
本文(已针对 Eclipse Mars 而更新)介绍如何使用 WebSphere Developer Tools (WDT) for Eclipse 快速创建一个 Hello World 应用程序并将它部署到 Liberty 服务器。像本系列的其他文章 (比如使用 IntelliJ IDEA 在 Liberty 上创建一个 Hello World 应用程序), 一样,我们将使用一个简单的 Hello World 应用程序,以便展示如何使用各种开发工具来开发它。
下载并启动Eclipse, 然后将这个按钮拖放到 Eclipse 工具栏,以打开 WDT 安装程序:(一种替代方法是,在 Eclipse 中单击 Help > Eclipse Marketplace…然后搜索适合您的 Eclipse 版本的 WebSphere Developer Tools。)
安装 WDT(且 IDE 正在运行)后,下一步是创建一个项目。这一步可以从 Web 或 Java EE 透视图使用 File > New > Web Project 轻松完成。
在 New Project 向导中,输入 Hello World
作为项目名称,确保项目模板为 Simple 且 Programming Model 为 Java EE,然后单击
Next。
确保已选择 Deployment,对于 Target Runtime,单击 New…。
选择 WebSphere Application Server Liberty Profile 并单击 Next。
输入您的 WAS Liberty 安装路径并单击 Finish。 如果还没有安装 WAS Liberty,可以选择 Install from an archive or a repository,然后单击 Next。
输入您希望将 WAS Liberty 安装到的位置,然后选择希望使用的安装来源。如果还没有下载它,可以选择 Download and install a new runtime environment from: 来显示来自 Liberty Repository 的可用运行时选项。选择 V8.5.5.x 版本,然后单击 Next。
如果选择 Full Platform,您将需要配置您在第 17 步中创建的服务器中的 server.xml
文件。
不需要为此应用程序安装任何加载项,所以再次单击 Next,然后接受许可并单击 Finish。安装 WAS Liberty 且创建服务器后,返回到 New Web Project 向导。
清除 Add project to an EAR 复选框并单击 Finish。
要创建本示例中使用的简单 JSP,可右键单击 Hello World 项目并单击 New > Web Page。
输入 index.jsp
作为 File name ,确保选择了 Basic Templates > JSP 。单击 Finish。
WDT 将为您创建并打开该 JSP。
在 <body> 和 </body> 标签之间,添加:
<h1>Good <% if (new GregorianCalendar().get(Calendar.HOUR_OF_DAY) < 12) {%><br />Morning<br /><% } else { %><br />Afternoon<br /><% } %></h1>
如果您在键入类名后按 CTRL-Space(在 Mac 上按 CMD-Space),WDT 将自动向 JSP 中添加所使用的 Java 类的导入语句。这会在 jsp 文件顶部添加以下导入语句:
<%@page import="java.util.Calendar"%> <%@page import="java.util.GregorianCalendar"%>保存该文件。我们现在已准备好部署我们的应用程序。 右键单击 Hello World 并选择 Run As > Run on Server。 因为还没有为 IDE 定义服务器,所以我们需要定义一个。选择 Manually define a new server ,然后选择 IBM > WebSphere Application Server Liberty Profile 并单击 Next。
单击 Finish.
WDT 将开始部署该应用程序,启动服务器,并在集成的 Web 浏览器中为您打开该网页:
不仅如此,它还会从 Eclipse 工作区运行该应用程序,为您提供最快的编辑、编译、运行和调试周期。
在developerWorks上的相关资源:
在 5 分钟内通过 10 个简单步骤集成 JRebel 与 Liberty
本文翻译自:Get started with a Hello World app on Liberty using WebSphere Developer Tools for Eclipse(2017-01-05)
The post 使用 WebSphere Developer Tools for Eclipse 在 Liberty 上创建一个 Hello World 应用程序 appeared first on developerWorks Developer Center -- 中国(Beta).
文章来源:
Author:developerWorks中国
link:https://developer.ibm.com/cn/blog/2017/developing-applications-wdt-liberty-profile/