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

docker: storage and services

Docker Volume Without going through Docker, accessing files within a Docker image is not easy. Therefore, Docker has a volume feature that allows users to specify the location on the host file system to serve as the access directory for Docker. In other words, a volume is the NFS of a Docker image. Example: Using a volume to store SQLite files. ref:  SQLite for NodeJS: https://www.sqlitetutorial.net/sqlite-nodejs/ Initialize the project. # Setup ExpressJS framework express --view=pug 240324_ejs_sqlite_docker npm init npm install express npm install sqlite3 Test: npm start Initialize docker  Since the directory already contains NodeJS, the Docker Daemon will assist in the setup. Create new docker image docker build -t atfuture7/sqlite01 . Create a folder for Docker, create a container, run it.  mkdir docker_vol docker run -p 3000:3000 -v ./docker_vol:/data --name exp_sqlite atfuture7/sqlite01 After confirming that the container can run co...

Guide to Preserving HuggingFace Models in Google Colab Environments

Conclusion:  Step 1:  find the model path: ls ~/.cache  Step 2:  Copy the entire folder to Google Drive:  Step 3:  Set model path to the subfolder under snapshot: My Story: I initially began exploring Generative AI (GAI) and Google Colab through Stable Diffusion. In the past, as I mainly wrote server services and console applications, I was less familiar with data science modes like R and Jupyter that can maintain a paused state. I didn't quite understand the heavy burden on Colab of creating a temporary Stable Diffusion WebUI with .ipynb, as suggested by popular guides. I just found it troublesome that connections often took a long time and then dropped, requiring a restart. Recently, while testing new versions of the Stable Diffusion model, and facing challenges due to Colab's policies making various versions of WebUI difficult to run successfully, I started researching how to write my own test programs in Colab. Eventually, I understood that Colab is ess...

Review old/new stuff: Angular 17

When I reviewed Angular recently, I discovered that it had just undergone a major revision three months ago, v17. The notes here are summaries of common features incorporated into v17. Install Angular ref: https://angular.io/guide/setup-local npm install -g @angular/cli Create new project ng new proj_name cd proj_name If the old project needs to be migrated to v17 control flow: ref: https://youtu.be/36Hcx7kRYDg?si=pmZcRkQHIlmguK3K ng generate @angular/core:control-flow Activate  ng serve Data Flow ref: https://angular.io/tutorial/first-app/first-app-lesson-09 Service can be regarded as a custom class (similar to custom modules written in expressJS) ng generate service obj_name In the sample program, enumeration of array is used. this.housingLocationList.find(housingLocation => housingLocation.id === id); The concept is  find( function(element) => { return (condition; )}) ref:  https://developer.mozilla.org/en-US/docs/Web/JavaScript...