WebSphere Liberty for Windows development environment maintenance procedure

Introduction

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

Introduction of Liberty

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. image01.JPG

By the way, there seems to be such a thing. I haven't tried this. Free version: WebSphere Application Server for Developers V8.5

Maintaining Eclipse as a Liberty development environment

Eclipse introduction

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!

Install WebSphere Developer Tools

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. image02.JPG

Then, the wizard for installing WebSphere Developer Tools on Eclipse will be launched. Follow the wizard to proceed with the installation. image03.JPG

After installation, restart Eclipse.

Creating a Liberty runtime environment on Eclipse

Select Window --Show View to display the Runtime Explorer view. image04.JPG

Right-click on the Runtime Explorer view --New --Runtime Environment ... image05.JPG

Specify the name, specify the Liberty directory (wlp directory) that you obtained and expanded earlier, and create the runtime environment. image06.JPG

Creating a Liberty server

Right click on the entry created above --New --Liberty Server image07.JPG

Create Liberty server by specifying server name image08.JPG

Create a server definition so that Eclipse can recognize the created Liberty server. Right click in server view --New --Server image09.JPG

Create a server definition by specifying the Liberty server created earlier! image10.JPG

image11.JPG

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!

Operation example

Change server definition

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) image11_01.JPG

Web application development

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.

Project creation

Right-click in the Project Explorer view of the Eclipse Web Perspective --New --Project, select Dynamic Web Project image13.JPG

Create a project by setting the project name and other necessary parameters. image14.JPG

A project gala is created like this. image15.JPG

JavaBean creation

Right-click on the Java Resources src and select --New --Package to create the package. image16.JPG

Right click on the created package --New --Class Specify the Class name, and create other than that with the default settings. image17.JPG

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;
	}

}

image18.JPG

Servlet creation

Right click on the same package as above --New --Select Servlet Specify the servlet name, otherwise create with the default. image17.JPG

A Servlet template is created like this. image20.JPG

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);
	}

}

JSP creation

Right-click on the Web Content --New --Select JSP File. Specify the JSP name, otherwise create with the default. image21.JPG

A JSP template is created like this. image22.JPG

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>

test

Let's deploy the app created above on the Liberty server and test it.

Deploy

Right-click on the Liberty server in the Servers view and select Add and Remove. image23.JPG

Select the project "Sample02" to be deployed and press Add. (Move to the right column) image24.JPG

Sample02 is deployed. image25.JPG

Right-click on the server and select Start to start the server.

Test run

Right-click the Servlet "Servlet01.java" you want to run and select --Run As --Run on Server. image26.JPG

Select the server to run. image27.JPG

The Servlet execution result is displayed by the browser function of Eclipse. image28.JPG

Try specifying the Query String. (Add "? Data01 = AAAAA" to the end of the URL) image29.JPG

It looks like it worked!

export

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. image30.JPG

Export by specifying the file name etc. image31.JPG

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

WebSphere Liberty for Windows development environment maintenance procedure
[Procedure 1 for beginners] Ruby on Rails: Construction of development environment
Environment construction for Servlet application development
Amazon Corretto for Windows installation procedure
[Unity] Android development environment construction procedure
Build Java development environment (for Mac)
CentOS8 + Anaconda + Django development environment construction procedure
Modern Java environment for Windows using Chocolatey
Procedure for introducing Docker into the development environment of existing Rails applications [Rails, MySQL, Docker]
Build a development environment for Docker + Rails6 + Postgresql
Build a development environment for Docker, java, vscode
Java development environment
Stable development environment construction manual for "Rails6" with "Docker-compose"
[Java] Environment construction procedure for developing struts 1.3 with Eclipse
Java SE Development Kit (JDK) setup procedure on Windows
Create Chisel development environment with Windows10 + WSL2 + VScode + Docker