angelcool@lolcahost:~/code-learning/Java/spring-boot$ date
Sun Jun 1 12:30:32 PM PDT 2025
angelcool@lolcahost:~/code-learning/Java/spring-boot$ pwd
/home/angelcool/code-learning/Java/spring-boot
# INITIALIZE APPLICATION
angelcool@lolcahost:~/code-learning/Java/spring-boot$ spring init -a my-demo -l java --build maven -x my-demo
Using service at https://start.spring.io
Project extracted to '/home/angelcool/code-learning/Java/spring-boot/my-demo'
angelcool@lolcahost:~/code-learning/Java/spring-boot$
# INSTALL MAVEN
angelcool@localhost:~/code-learning/Java/spring-boot/my-demo$ sudo dnf install maven
...
angelcool@localhost:~/code-learning/Java/spring-boot/my-demo$ mvn --version
Apache Maven 3.9.6 (Red Hat 3.9.6-7)
...
# RUN APPLICATION, NOTE: I think I had to update the artifactId in pom.xml to 'spring-boot-starter-web'
angelcool@localhost:~/code-learning/Java/spring-boot/my-demo$ mvn spring-boot:run
...
# MAKE REQUEST
angelcool@localhost:~/code-learning/Java/spring-boot/my-demo$ http http://localhost:8080/coffees
HTTP/1.1 200
Connection: keep-alive
Content-Type: application/json
Date: Mon, 02 Jun 2025 03:13:46 GMT
Keep-Alive: timeout=60
Transfer-Encoding: chunked
[
{
"id": "3d1256a7-c5c8-4a9b-9ef3-60da3107b06b",
"name": "Black"
},
{
"id": "7fc475b2-7c39-4412-baeb-6ac01f46128c",
"name": "French Vanilla"
},
{
"id": "690c16af-3931-4dbd-b573-a9d8c86e0a3c",
"name": "Hazelnut"
}
]
# SOURCE CODE
angelcool@localhost:~/code-learning/Java/spring-boot/my-demo$ cat src/main/java/com/example/my_demo/DemoApplication.java
package com.example.my_demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
// import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
// import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
// import org.springframework.ui.Model;
import java.util.ArrayList;
import java.util.List;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.UUID;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
class Coffee {
private final String id;
private String name;
public Coffee(String id, String name) {
this.id = id;
this.name = name;
}
public Coffee (String name) {
this(UUID.randomUUID().toString(),name);
}
public String getId(){
return this.id;
}
public String getName(){
return this.name;
}
public void setName(String name){
this.name = name;
}
}
@RestController
class RestApiController{
private List<Coffee> coffees = new ArrayList<>();
public RestApiController(){
this.coffees.addAll(List.of(
new Coffee("Black"),
new Coffee("French Vanilla"),
new Coffee("Hazelnut")
));
}
@RequestMapping(value = "/coffees", method = RequestMethod.GET)
Iterable<Coffee> getCoffees() {
return this.coffees;
}
}
[ view entry ] ( 20 views ) | print article
angelcool@localhost:~$
angelcool@localhost:~$ date
Sat May 31 04:57:16 PM PDT 2025
angelcool@localhost:~$ cat /etc/redhat-release
Fedora release 41 (Forty One)
angelcool@localhost:~$
# INSTALL SDKMAN
angelcool@localhost:~$ curl -s "https://get.sdkman.io" | bash
...
# CHECK SDKMAN VERSION
angelcool@localhost:~$ sdk version
SDKMAN!
script: 5.19.0
native: 0.7.4 (linux x86_64)
# INSTALL SPRING BOOT CLI
angelcool@localhost:~$ sdk install springboot
...
# CHECK SPRING BOOT CLI VERSION
angelcool@localhost:~$ spring --version
Spring CLI v3.5.0
angelcool@localhost:~$
angelcool@localhost:~$
[ view entry ] ( 22 views ) | print article
angelcool@fedora-laptop$date
Sat Nov 23 05:57:16 PM PST 2024
angelcool@fedora-laptop$
angelcool@fedora-laptop$
angelcool@fedora-laptop$java --version
openjdk 17.0.13 2024-10-15
OpenJDK Runtime Environment (Red_Hat-17.0.13.0.11-1) (build 17.0.13+11)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.13.0.11-1) (build 17.0.13+11, mixed mode, sharing)
angelcool@fedora-laptop$jar --version
jar 17.0.13
angelcool@fedora-laptop$
angelcool@fedora-laptop$pwd
/home/angelcool/java-practice/HelloWorldServlet
angelcool@fedora-laptop$tree
.
├── deploy
│ └── helloworld.war
├── Notes.txt
├── src
│ ├── HelloWorld.class
│ └── HelloWorld.java
└── web
└── WEB-INF
├── classes
│ └── com
│ └── coolwriter
│ └── helloworld
│ └── HelloWorld.class
└── web.xml
9 directories, 6 files
angelcool@fedora-laptop$
angelcool@fedora-laptop$cat Notes.txt
# Compile java class, this will create HelloWorld.class
angelcool@fedora-laptop$javac --class-path /usr/share/tomcat/lib/tomcat-servlet-api.jar src/HelloWorld.java
# Copy compiled .class file to WEB-INF
angelcool@fedora-laptop$cp src/HelloWorld.class web/WEB-INF/classes/com/coolwriter/helloworld/
# Create WAR file
angelcool@fedora-laptop$jar cvf deploy/helloworld.war -C web .
# Move WAR file to Tomcat webapps directory
angelcool@fedora-laptop$sudo cp deploy/helloworld.war /usr/share/tomcat/webapps/
# Reload servlet in /manager page ( or restart Tomcat I think )
# Access servlet: http://localhost:8080/helloworld/Hello
angelcool@fedora-laptop$
angelcool@fedora-laptop$
angelcool@fedora-laptop$cat web/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="4.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web- ... ">
<display-name>Hello World!</display-name>
<servlet>
<servlet-name>helloworld</servlet-name>
<servlet-class>com.coolwriter.helloworld.HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloworld</servlet-name>
<url-pattern>/Hello</url-pattern>
</servlet-mapping>
</web-app>
angelcool@fedora-laptop$
angelcool@fedora-laptop$
angelcool@fedora-laptop$cat src/HelloWorld.java
package com.coolwriter.helloworld;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class HelloWorld extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String msg = this.getGreeting();
out.println(msg);
}
private String getGreeting()
{
String msg = null;
int rand = (int) (Math.random() * (6)) +1;
switch (rand) {
case 1:
msg = "Hello There!";
break;
case 2:
msg = "Hello Friend!";
break;
case 3:
msg = "Hello Stranger!";
break;
case 4:
msg = "Hello! My name is Angel!";
break;
default:
msg = "Hello World!";
}
return msg;
}
}
angelcool@fedora-laptop$
angelcool@fedora-laptop$
[ view entry ] ( 202 views ) | print article
angelcool@fedora-laptop$date
Sat Nov 23 12:00:14 PM PST 2024
angelcool@fedora-laptop$
angelcool@fedora-laptop$
angelcool@fedora-laptop$cat /etc/redhat-release
Fedora release 39 (Thirty Nine)
angelcool@fedora-laptop$
angelcool@fedora-laptop$
angelcool@fedora-laptop$dnf info tomcat
Last metadata expiration check: 0:42:59 ago on Sat 23 Nov 2024 11:18:54 AM PST.
Installed Packages
Name : tomcat
Epoch : 1
Version : 9.0.96
Release : 1.fc39
Architecture : noarch
Size : 323 k
Source : tomcat-9.0.96-1.fc39.src.rpm
Repository : @System
From repo : updates
Summary : Apache Servlet/JSP Engine, RI for Servlet 4.0/JSP 2.3 API
URL : http://tomcat.apache.org/
License : ASL 2.0
Description : Tomcat is the servlet container that is used in the official Reference
: Implementation for the Java Servlet and JavaServer Pages technologies.
: The Java Servlet and JavaServer Pages specifications are developed by
: Sun under the Java Community Process.
:
: Tomcat is developed in an open and participatory environment and
: released under the Apache Software License version 2.0. Tomcat is intended
: to be a collaboration of the best-of-breed developers from around the world.
angelcool@fedora-laptop$
angelcool@fedora-laptop$sudo dnf install tomcat
...
angelcool@fedora-laptop$sudo dnf install tomcat-admin-webapps
...
angelcool@fedora-laptop$sudo dnf install tomcat-docs-webapp
...
angelcool@fedora-laptop$sudo systemctl start tomcat.service
...
Enable admin user, uncomment the following in /etc/tomcat/tomcat-users.xml
<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user name="admin" password="admin" roles="admin,manager,admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status" />
Restart server and go to: http://localhost:8080/manager/html
For reference:
angelcool@fedora-laptop$
angelcool@fedora-laptop$tree /usr/share/tomcat/webapps/
/usr/share/tomcat/webapps/
├── host-manager
│ ├── css
│ │ └── manager.css
│ ├── images
│ │ ├── asf-logo.svg
│ │ └── tomcat.svg
│ ├── index.jsp
│ ├── META-INF
│ │ └── context.xml
│ └── WEB-INF
│ ├── jsp
│ │ ├── 401.jsp
│ │ ├── 403.jsp
│ │ └── 404.jsp
│ ├── manager.xml
│ └── web.xml
└── manager
├── css
│ └── manager.css
├── images
│ ├── asf-logo.svg
│ └── tomcat.svg
├── index.jsp
├── META-INF
│ └── context.xml
├── status.xsd
├── WEB-INF
│ ├── jsp
│ │ ├── 401.jsp
│ │ ├── 403.jsp
│ │ ├── 404.jsp
│ │ ├── connectorCerts.jsp
│ │ ├── connectorCiphers.jsp
│ │ ├── connectorTrustedCerts.jsp
│ │ ├── sessionDetail.jsp
│ │ └── sessionsList.jsp
│ └── web.xml
└── xform.xsl
13 directories, 26 files
angelcool@fedora-laptop$
[ view entry ] ( 209 views ) | print article
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |