The interesting implementation of Java I proceed to is Spring. And, only getting Java running is not enough. I also need to set up Maven. This name is new to me, and I found many Spring tutorials just skip this part. At least I need Maven to generate templates for me. I should learn it more. ( I knew there is a great tool -- Eclipse -- can make tedious things disappear. I’m taking a strategy to install all experiments I want to try and throw away when it's full. And that's an external VM, not my PC. I, not yet, want to do research about installing Eclipse on AMI. )
Upgrade to Java 8
First is to upgrade Java on AMI to Java8. AWS provides advanced tools for Linux 2. And DIY for Linux2. At least there are solutions for my choice.
Amazon Corretto 8 Installation Instructions for Amazon Linux 2
Here are commands I used:
>wget */amazon-corretto-8-x64-linux-jdk.deb
>wget */amazon-corretto-8-x64-linux-jdk.rpm
>wget */amazon-corretto-8-x64-linux-jdk.tar.gz
>sudo yum localinstall java-1.8.0-amazon-corretto*.rpm
>java -version
Install Maven
Partially refer to this tutorial, I do appreciate it : HOW TO SETUP A SPRING BOOT APPLICATION ON AMAZON AWS
Maven download https://maven.apache.org/download.cgi
Here are commands I used:
>wget */apache-maven-3.6.3-bin.zip
>unzip apache-maven-3.6.3-bin.zip
>mv apache-maven-3.6.3/ maven/
>sudo maven /opt
>vi /etc/profile.d/maven.sh (add maven to PATH)
>source /etc/profile.d/maven.sh
>mvn -version
Create a basic package by Maven
I don’t want to and not suggest to copy-past the pom.xml content from other experts. And I’m just too lazy to generate the file structure the IDE required by hand. Those are generated and controlled by IDE, at least at initialization. The IDE has the latest version of its own templates.
Additional tutorial for Maven: Guide to Create a Simple Maven Project
Template Maven provided: https://maven.apache.org/archetypes/index.html
>mvn -B archetype:generate \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DgroupId=my.first.mvn \
-DartifactId=app-name>mvn compile
>mvn install
>java -cp app-name-0.0.1-SNAPSHOT.jar my.first.mvn.App>mvn -B archetype:generate \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DgroupId=some.group.id \
-Dpackage=my.first.mvn \
-DartifactId=app-name2(The previous command is used to test the file structure of -Dpackage)
Maven web app
I referred to Maven’s tutorial… but a little reluctant to admit. Because it didn’t use template and I spent a lot of time to figure out and found the resource from Apache. Anyway, I still need to list it, since I’m using it’s settings. Since I’m not going to upload the source files to GitHub, (these two samples focus more on using maven, java files are irrelevant). Anyone who wants to rebuild those samples can visit those tutorials, and takes my advice from this post.
Guide to Create a Simple Maven Web Application
>mvn -B archetype:generate \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DarchetypeArtifactId=maven-archetype-webapp \
-DarchetypeVersion=1.4 \
-DgroupId=my.second.mvn \
-Dpackage=my.first.mvn \
-DartifactId=app-web(I intentionally set the package name identical to my previous project. Then I can copy its file structure. )
>cp -r ../app-name/src/main/java/ ./src/main/(add dependencies of servlet and jsp)
>vi src/main/java/my/first/mvn/aServl.java
>vi pom.xml>vi src/main/webapp/WEB-ING/web.xml(add gitty)
>vi pom.xml
(Then got enough support to compile a servlet)>mvn jetty:app-web &(get content generated from jsp)
>wget http:localhost:8080/web-app/>wget http:localhost:8080/web-app/guesswho(get servlet response)>fg
>^c
Comments
Post a Comment