I needed to create a WebSphere Liberty development / test environment on Windows, so here's a summary of the steps I took at that time. For the time being, it is assumed that there should be an environment where you can create and test a simple web application. The goal is to run a web application developed with Eclipse on Liberty and check the operation on Windows alone.
reference: The basic work flow is based on the following articles. Installing WebSphere Liberty's Java EE local development environment
The target Liberty server version is like 16.0.0.3, so I'll get the same version.
When I googled with keywords such as Liberty, version, and download, the following sites were caught. 16.0.0.3: WebSphere Application Server Liberty 16.0.0.3
It seems that there are various forms of provision depending on the installation method, and there are various editions (?), So it is difficult to understand what to do! The zip file seems to be quick, so select "wlp-javaee7-16.0.0.3.zip" from the link above and download it. (You will be taken to IBM's fix central, a site where you can get Fix, and download from there. It seems that you can get it if you have an IBM ID.)
Then, unzip the zip and it's OK.
By the way, there seems to be such a thing. I haven't tried this. Free version: WebSphere Application Server for Developers V8.5
Eclipse IDE for Java EE Developers Get the latest Eclipse Neon.3 (4.6.3) from the above site. This also just unzips the zip. Then, execute eclipse.exe and specify an appropriate workspace folder to start it!
Installing WebSphere Developer Tools in Eclipse seems to make it easier to manage the Liberty server from Eclipse.
There is such a site (↓). Assets and tools for Liberty are provided. IBM WebSphere Liberty Repository
From this site, select Developer Tools (↓) for Neon. https://developer.ibm.com/assets/wasdev/#asset/tools-WebSphere_Developer_Tools_for_Eclipse_Neon
Drag and drop the Install button on this site into the Eclipse window.
Then, the wizard for installing WebSphere Developer Tools on Eclipse will be launched. Follow the wizard to proceed with the installation.
After installation, restart Eclipse.
Select Window --Show View to display the Runtime Explorer view.
Right-click on the Runtime Explorer view --New --Runtime Environment ...
Specify the name, specify the Liberty directory (wlp directory) that you obtained and expanded earlier, and create the runtime environment.
Right click on the entry created above --New --Liberty Server
Create Liberty server by specifying server name
Create a server definition so that Eclipse can recognize the created Liberty server. Right click in server view --New --Server
Create a server definition by specifying the Liberty server created earlier!
Now you have an environment where you can edit server.xml from Eclipse, start / stop the Liberty server, and deploy / test apps developed on Eclipse!
In the Enterprise Explorer view, expand the server definition you created and double-click server.xml. The editor for configuration will open, so add features as appropriate. (You can also edit the source directly)
I would like to create a simple web app. Assuming an MVC model, let's create a simple one that uses Servlet, JavaBean, and JSP.
Right-click in the Project Explorer view of the Eclipse Web Perspective --New --Project, select Dynamic Web Project
Create a project by setting the project name and other necessary parameters.
A project gala is created like this.
Right-click on the Java Resources src and select --New --Package to create the package.
Right click on the created package --New --Class Specify the Class name, and create other than that with the default settings.
A template will be created, so create the code as follows.
JavaBean01.java
package sample.test01;
public class JavaBean01 {
private String strData01="InitialData";
public String getStrData01() {
return strData01;
}
public void setStrData01(String strData01) {
this.strData01 = strData01;
}
}
Right click on the same package as above --New --Select Servlet Specify the servlet name, otherwise create with the default.
A Servlet template is created like this.
Create the code as below.
Servlet01.java
package sample.test01;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class Server01
*/
@WebServlet("/Servlet01")
public class Servlet01 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Servlet01() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//Get parameters from Query String
String strQueryData01 = request.getParameter("Data01");
//Variable declaration of JavaBean object
JavaBean01 javaBean01 = null;
//Get JavaBean from Session object. Generate if not.
HttpSession session = request.getSession();
javaBean01 = (JavaBean01)session.getAttribute("sessionObject_JavaBean01");
if (javaBean01 == null){
javaBean01 = new JavaBean01();
session.setAttribute("sessionObject_JavaBean01", javaBean01);
}
//Set the data received as a parameter in JavaBean
if (strQueryData01 != null) {
javaBean01.setStrData01(strQueryData01);
}
//JSP call
RequestDispatcher requestDispatcher = request.getRequestDispatcher("./JSP01.jsp");
requestDispatcher.forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
Right-click on the Web Content --New --Select JSP File. Specify the JSP name, otherwise create with the default.
A JSP template is created like this.
Create the code as below.
JSP01.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
import="sample.test01.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%--JavaBean generation--%>
<jsp:useBean id="sessionObject_JavaBean01" class="sample.test01.JavaBean01"
scope="session" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Simple Web Application</title>
</head>
<body>
<h1>Simple Web Application</h1>
<br>
Data01: <jsp:getProperty name="sessionObject_JavaBean01" property="strData01" />
<br>
</body>
</html>
Let's deploy the app created above on the Liberty server and test it.
Right-click on the Liberty server in the Servers view and select Add and Remove.
Select the project "Sample02" to be deployed and press Add. (Move to the right column)
Sample02 is deployed.
Right-click on the server and select Start to start the server.
Right-click the Servlet "Servlet01.java" you want to run and select --Run As --Run on Server.
Select the server to run.
The Servlet execution result is displayed by the browser function of Eclipse.
Try specifying the Query String. (Add "? Data01 = AAAAA" to the end of the URL)
It looks like it worked!
bonus. If you want to bring this app to another Liberty server, you can export it as a WAR file. Right-click on the project you want to export and select --Export --WAR file.
Export by specifying the file name etc.
This will create it as a WAR file, so you can take it to the Liberty server you want to deploy. (The rest of this article is not the intended range of this article, so it is omitted.)
Recommended Posts