Try to build Java8 environment on Amazon Linux2

Overall flow

  1. [EC2] Java8 environment construction on Amazon Linux2
  2. [Local] Create a Spring project locally
  3. Start the [EC2] Spring project

Java8 environment construction on Amazon Linux2

1. Connect to EC2 instance with ssh

$ ssh -i <key name> .pem ec2-user @ <public IP address>

2. Install JRE

$ sudo yum search java | grep jdk $ sudo yum install -y java-1.8.0-openjdk.x86_64

$ sudo yum search java | grep jdk
ldapjdk-javadoc.noarch : Javadoc for ldapjdk
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment 8
java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.8.0-openjdk-accessibility-debug.x86_64 : OpenJDK 8 accessibility
java-1.8.0-openjdk-debug.x86_64 : OpenJDK Runtime Environment 8 with full debug
java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos 8
java-1.8.0-openjdk-demo-debug.x86_64 : OpenJDK Demos 8 with full debug on
java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment 8
java-1.8.0-openjdk-devel-debug.x86_64 : OpenJDK Development Environment 8 with
java-1.8.0-openjdk-headless.x86_64 : OpenJDK Headless Runtime Environment 8
java-1.8.0-openjdk-headless-debug.x86_64 : OpenJDK Runtime Environment with full
java-1.8.0-openjdk-javadoc.noarch : OpenJDK 8 API documentation
java-1.8.0-openjdk-javadoc-debug.noarch : OpenJDK 8 API documentation for
java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK 8 API documentation compressed
java-1.8.0-openjdk-javadoc-zip-debug.noarch : OpenJDK 8 API documentation
java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle 8
java-1.8.0-openjdk-src-debug.x86_64 : OpenJDK Source Bundle 8 for packages with
ldapjdk.noarch : The Mozilla LDAP Java SDK

Install JRE 1.8.0

$ sudo yum install -y java-1.8.0-openjdk.x86_64

Check the Java version

$ java -version

$ java -version
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)

It is 1.8.0 properly.

Create a Spring project locally

A jar file or Java Archive is a ZIP format compressed file that includes class files and image data included in a Java project.

Copy this file to the EC2 side and build it.

1. Generate a jar file from your project

Move to the local (your PC) Spring project directory and generate a jar file with the command

$cd project directory
$ mvn clean package

2. Copy the file with sftp

## sftp connect
$ sftp -i <key name>.pem ec2-user@<Public IP address>
## file put
sftp> put target/<file name>.jar

important point

--Set the java version of the Spring Boot project to 8

-> Play with the property in pom.xml

<properties>
	<java.version>8</java.version>
</properties>

-> Change environment path

$ cd ~/.zshrc
$ vi .zshrc
##Add the following settings
export JAVA_HOME=`/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java_home -v "1.8"`
PATH=$JAVA_HOME/bin:$PATH

-> Don't forget to update at the end

$ source ~/.zshrc

Start Spring project

1. Connect to EC2 instance with ssh

$ ssh -i my-key.pem ec2-user @ <public IP address>

2. Build the project with java command

$ java -jar <filename> .jar

$ java -jar todo-app-0.0.1-SNAPSHOT.jar 

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.3.RELEASE)

...

Changes in AWS

Security Group changes --Allow inbound rules to connect to port 8080

Recommended Posts

Try to build Java8 environment on Amazon Linux2
Install java 1.8.0 on Amazon linux2
Try to build a Java development environment using Docker
Build a Java development environment on Mac
Build Java 8 development environment on AWS Cloud9
Install Java8 with Yum on Amazon Linux
How to install kafkacat on Amazon Linux2
Try Azure Service Fabric (Java) on Mac-Local Environment
[Java] Build Java development environment on Ubuntu & check execution
Install Java, Apache, Tomcat9 on EC2 (Amazon Linux2)
Build a Java runtime environment on Sakura VPS
How to build a Pytorch environment on Ubuntu
How to build Java development environment with VS Code
Downgrade Java on openSUSE Linux
Install rbenv on Amazon Linux
Run R from a tomcat-powered Java process on Amazon Linux
What happened in "Java 8 to Java 11" and how to build an environment
[Java] How to update Java on Windows
Build Java development environment (for Mac)
Build a XAMPP environment on Ubuntu
[Java] Try to implement using generics
Try to extract java public method
Try to implement Yubaba in Java
How to build vim on Ubuntu 20.04
Build Unity development environment on docker
Try "Introduction to Vert.x" on Gradle
Install Java development environment on Mac
Notes on building Kotlin development environment and migrating from Java to Kotlin
Steps to build a Ruby on Rails development environment with Vagrant
Install PHP7.4 to build CentOS7 Laravel environment
How to check Java installed on Mac
Java runtime environment construction method (Tomcat @ Linux)
Try to solve Project Euler in Java
How to build a Ruby on Rails environment using Docker (for Docker beginners)
Try to implement n-ary addition in Java
Enable Docker build cache on GitHub Action and deploy to Amazon ECS
Java development environment construction memo on Mac
How to switch Java versions on Mac
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
Build Redmine code reading environment on Docker
Build OpenCV with Java Wrapper on Ubuntu 18.04
I tried to build AdoptOpenjdk 11 on CentOS 7
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
Build an environment with Docker on AWS
Build a JMeter environment on your Mac
Try the Docker environment on AWS ECS
Build an Ultra96v2 development environment on Docker 1
[Linux convenient command] Try to insert delta
Steps to register Java files on GitHub
How to build Rails 6 environment with Docker
Build Web Application Server (Java) on VPS
[Even beginners can do it! ] How to create Java environment on Windows 10 (JDK14.0.1)
Build a development environment to create Ruby on Jets + React apps with Docker
Build an environment where you can try Rails Girls or el-training on Clound9
Try using Firebase Cloud Functions on Android (Java)
Try running ScalarDB on WSL Ubuntu (Environment Construction)
Try to create a bulletin board in Java
Try to link Ruby and Java with Dapr
Build Java environment and output hello world [Beginner]
Road to Java Engineer Part1 Introduction & Environment Construction
Increment behavior Try to make Java problem TypeScript 3-4