I built a Java EE environment on AWS and tried running a web application

2019/10/7 Full revision

============================================================================= Hello. It is zd6ir7. It has been a long time since Last post. This time, I will post a memo when I built a Java EE environment on AWS and deployed and ran a web application there. The application to be run this time is the Web application of the online shop of "Miscellaneous goods store.com" that appears at the end of "Introduction to Easy-to-understand JavaEE Web System" (Note 1) ).

** 1. Software configuration ***

The software configuration of the AWS EC2 environment realized this time is as follows.

--OS: Linux kernel version 4.14

** 2. Construction / execution procedure **

The procedure for building the environment and running the Web application this time is as follows.

1. 1. Build a new AWS Colud9 environment

Create an AWS account by referring to the article "First introduction of AWS Cloud9". Create an EC2 instance of Amazon Linux from the EC2 menu in the management console.

2. Java update

Java is included in the environment, but it has been updated to Java 8 based on the article "Building Java 8 development environment with AWS Cloud9".

3. 3. Introduction of glassfish.

Install glassfish 5.0.1 (Note 2) by referring to the article "Memo for building AWS + GlassFish 4.1". When you type the wget command, you need to specify the download source URL of glassfish5.0.1, but specify the URL of v5.0.1 from glassfish download site. Derby (JavaDB) is installed at the same time as glassfish is installed. Leave glassfish running for later steps.

Four. Start Derby

The Web application to be run this time needs to be connected to the database. Since the connection will be set later, 3. Start Derby installed in (Note 3).

sudo bin/asadmin start-database
Starting database in Network Server mode on host 0.0.0.0 and port 1527.
--------- Derby Network Server Information --------
Version: CSS10100/10.10.2.0 - (1582446)  Build: 1582446  DRDA Product Id: CSS10100
(Omission)

Starting database in the background.
Log redirected to /opt/glassfish4/glassfish/databases/derby.log.
Command start-database executed successfully.

Five. Security group settings

Added security settings to the AWS EC2 environment to access the glassfish console screen and applications from a PC. Specifically, select the relevant security group from the EC2 menu of the AWS console, and specify the protocol, port number, and access source IP address you want to access the AWS EC2 environment on the "Inbound" tab. In the figure below, the default port number 8080 for glassfish, the port number 4848 for the glassfish management console, and the port number 22 for SSH are set to pass. security_group.png

6. Obtaining host name and IP address

Five. In addition, it is necessary to obtain information on the access destination host name or IP address. As shown in the figure below, you can refer to this information by selecting the relevant environment from the EC2 menu of the AWS console. ホスト名とIPアドレス.png

7. 7. glassfish start

From a PC browser, https: // <6. Host name or access destination IP address obtained in>: 4848 / Go to and launch the glassfish management console. 3. 3. Since I also set it to pass https, depending on the browser, you may be asked if you want to browse this site, but continue browsing as it is. As shown in the figure below, you will be prompted to enter your user name and password. Log in by entering the user name and password set in. glassfishコンソール画面.png

8. 8. Connection settings with Derby

Set the data source from the glassfish management console screen logged in in 7. Specifically, the following two steps are taken.

--Create a new connection pool by pressing "New" from the "JDBC" menu> "JDBC Connection Pools" on the left side of the management console. Set based on the information in "Introduction to Easy-to-understand Java EE Web System". Created here with the name "Derby Pool". The figure below shows the situation when communicating from this connection pool to the Derby database. --Similarly, press "New" from the "JDBC" menu> "JDBC Resources" to create a data source. Give the JNDI name to the "Derby Pool" created above. Following the same book, the JNDI name is "jdbc / mydb".

DBへの接続.png

9. Deploy web application

Place the "General store.com" application war file in the deployment directory. For this placement, upload the file from the PC using "SCP" of Tera Term. Since glassfish is in the running state, glassfish reads it and executes the deployment process when it is placed. The following is an excerpt of the server log at the time of deployment.

[2019-10-07T11:38:08.497+0900] [glassfish 5.0] [INFO] [AS-WEB-GLUE-00172] [javax.enterprise.web] [tid: _ThreadID             =53 _ThreadName=AutoDeployer] [timeMillis: 1570415888497] [levelValue: 800] [[
  Loading application [zakka-ya-san] at [/zakka-ya-san]]]

[2019-10-07T11:38:08.617+0900] [glassfish 5.0] [INFO] [] [javax.enterprise.system.core] [tid: _ThreadID=53 _Thre             adName=AutoDeployer] [timeMillis: 1570415888617] [levelValue: 800] [[
  zakka-ya-san was successfully deployed in 9,423 milliseconds.]]

[2019-10-07T11:38:08.619+0900] [glassfish 5.0] [INFO] [NCLS-DEPLOYMENT-02035] [javax.enterprise.system.tools.dep             loyment.autodeploy] [tid: _ThreadID=53 _ThreadName=AutoDeployer] [timeMillis: 1570415888619] [levelValue: 800] [             [
  [AutoDeploy] Successfully autodeployed : /opt/glassfish5/glassfish/domains/domain1/autodeploy/zakka-ya-san.war             .]]

Ten. Web application execution

From your PC browser, http: // <6. Access the host name or access destination IP address obtained in>: 8080 / zakka-ya-san / and execute the "General store.com" application. A shopping site for learning appears (Note 4)

アプリケーション起動画面.png

** 3. in conclusion**#

There were some difficult points, but I was able to build it in a surprisingly short period of time. It's a really convenient time because you can easily create an environment. Thank you for reading this far.

footnote#

(Note 1) For details of the application, refer to Chapter 18 of the same book. To be exact, it is after the last exercise. (Note 2) With glassfish5.0, I do "asadmin restart-domain" in "AWS + GlassFish 4.1 build memo", but there is an error It will become. See stackoverflow article for more information. Since the problem has been solved in the higher version, glassfish 5.0.1, I decided to use the same version here. (Note 3) Please refer to the following URL for details on the start / stop operation of Derby. https://docs.oracle.com/cd/E19159-01/820-3956/genej/index.html (Note 4) Originally a learning application, you can't shop here! !!

Recommended Posts

I built a Java EE environment on AWS and tried running a web application
I tried running Java on a Mac terminal
I tried using Log4j2 on a Java EE server
I tried to modernize a Java EE application with OpenShift.
I tried running a Docker container on AWS IoT Greengrass 2.0
I tried running a DB access application on IKS + Db2 on IBM Cloud (6. Preparation of DB access application (java))
I tried running Ansible on a Docker container
Create a JAVA WEB application and try OMC APM
[For beginners] Until building a Web application development environment using Java on Mac OS
I tried to create a java8 development environment with Chocolatey
I tried to implement a buggy web application in Kotlin
I tried to develop a web application from a month and a half of programming learning history
I tried running a letter of credit transaction application with Corda 1
I tried to create a Spring MVC development environment on Mac
AWS Elastic Beanstalk # 1 with Java starting from scratch-Building a Java web application environment using the EB CLI-
I built a rails environment with docker and mysql, but I got stuck
4. Creating a manifest and running a web module
I tried running Docker on Windows Server 2019
I tried to make a machine learning application with Dash (+ Docker) part1 ~ Environment construction and operation check ~
I was a little addicted to running old Ruby environment and old Rails
Creating a java web application development environment with docker for mac part1
Java beginner tried to make a simple web application using Spring Boot
Build a web application development environment that uses Java, MySQL, and Redis with Docker CE for Windows
I tried to build a Firebase application development environment with Docker in 2020
I want to create a dark web SNS with Jakarta EE 8 with Java 11
Build a Java development environment on Mac
Build Java 8 development environment on AWS Cloud9
Deploy a Java web app on Heroku
[Java] Deploy a web application created with Eclipse + Maven + Ontology on Heroku
I tried to make a talk application in Java using AI "A3RT"
Volume of trying to create a Java Web application on Windows Server 2016
How to migrate a web application created in a local docker environment to AWS
Create a java web application development environment with docker for mac part2
Build Web Application Server (Java) on VPS
I built a CentOS 8 environment with Vagrant and tried to sync_folder, but I got an error, so I solved it.
[First environment construction] I tried to create a Rails 6 + MySQL 8.0 + Docker environment on Windows 10.
I tried to clone a web application full of bugs with Spring Boot
[Azure] I tried to create a Java application for free-Web App creation- [Beginner]
I tried putting Java on my Mac easily
java I tried to break a simple block
Build a Laravel environment on an AWS instance
I built a Code Pipeline with AWS CDK.
Prepare a scraping environment with Docker and Java
Build a Java runtime environment on Sakura VPS
I tried to break a block with java (1)
left4dead2 I made a Docker image for the server and tried running it on GCE # 3 (I had a hard time building the server)
I tried to create a shopping site administrator function / screen with Java and Spring
I tried deploying a page made with antique Middleman on Azure Static Web Apps
[Azure] I tried to create a Java application for free ~ Connect with FTP ~ [Beginner]
I want to implement it additionally while using kotlin on a site running Java
Create a Java development environment using jenv on Mac
I tried Mastodon's Toot and Streaming API in Java
Build a Ruby on Rails development environment on AWS Cloud9
I built an Ubuntu environment on Windows 10 using WSL2.
Compile with Java 6 and test with Java 11 while running Maven on Java 8
I tried to operate SQS using AWS Java SDK
I tried to create a Clova skill in Java
I tried to make a login function in Java
I tried using YOLO v4 on Ubuntu and ROS
I tried OCR processing a PDF file with Java
A memo when I tried "Talking about writing a Java application in Eclipse and publishing it in Kubernetes with a Liberty container (Part 1)"