Skip to main content

Setup Maven and two basic projects

    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
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
 
>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/
>vi src/main/java/my/first/mvn/aServl.java
>vi pom.xml
(add dependencies of servlet and jsp)
>vi src/main/webapp/WEB-ING/web.xml
>vi pom.xml
(add gitty)
(Then got enough support to compile a servlet)
>mvn jetty:app-web &
>wget http:localhost:8080/web-app/
(get content generated from jsp)
>wget http:localhost:8080/web-app/guesswho 
(get servlet response)
>fg
>^c


 

Comments

Popular posts from this blog

Bookmark service (MongoDB & Spring REST) -2/2

    I accidentally deleted my development VM. I got lucky having the habit of taking notes. This blog is useful. Development VM is doom to be lost. Rebuild it waste time, but having a clean slate is refreshing~. What concerns me more is my AWS free quota this month is reaching 85%. The second VM I launched but never being used might be the one to blame. (Of course, my mistake.) I terminated the wrong VM. Now I got Linux 2 built. Great, just threw away everything happened on AMI.  1st layer: Page Page class   Originally, I need to prepare getter/setter for all class properties for Spring. By using lombok, I only need to create constructors. lombok will deal with getter/setter and toString(). But there are chances to call getter/setter, but how? .......Naming convention.... Capitalize the 1st character with the prefix get/set.  Annotation @Data was used on this class.  Repository class Spring Docs: Repository https://docs.spring.io/spring-data/mongodb/docs/3....

gamer's interview

This project simulates a gamer's interview. Based on NodeJS+ ReactJS The setting is interviewing a gamer/journalist what's his/her plan of March 2020? The gamer answers his/her game list in plan, how many reviews on demand and how many hours expected. Games selected for review take 5 hours for each, while others take one. This project is designed to practice render html, jsx, component, props introduced in  https://www.w3schools.com/REACT/default.asp . Also fixed other issues to make it work. When trying to modualize objects and tools, my design developed to separate views and processes. And it is quite similar to the initialized structure NodeJS+ReactJS provided. Furthermore, since include local module files are banned by browsers, use NodeJS service seems to be the best option. view file main process object tool

Comments for my Server/Client Web API samples

        Finally, I finished the comments for python/07 and 09 projects. I almost forgot to put the date on source code which is used to note how long it took me. Not precisely in hours….. I didn’t include source code in my previous post. If choosing code-section for this post…… maybe I want to mark out my comment….. (Really?!)          Once my work was developing websites for enterprises, including ERP, CRM or content sites. The sustainability of network and security are important issues. There are 2 methods for HTML Form submission: GET and POST. Submit via POST is secure, compared to GET which piles parameters on URL. RESTful API is mainly using GET.         Yup, even if you have a certification key, if you put the value on the URL, it is visible data. When writing socket-communication, client-server sockets are a pair; both follow the agreement on commands and structures; and there are countless ports for usa...