Tomcat_configuration

Installation

1
sudo pacman -S tomcat10

Configuration

follow archwiki

Run

use /usr/share/tomcat/bin/{startup.sh,shutdown.sh,..} to start and stop tomcat

Web Application

This is my web application project structure.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
.
├── lib
├── Makefile
├── src
│   └── ie
│       └── ucd
│           └── comp2013J
│               ├── Department.java
│               ├── EmployeeDAO.java
│               ├── Employee.java
│               ├── JDBCTool.java
│               ├── UserDAO.java
│               └── User.java
├── target
│   └── ie
│       └── ucd
│           └── comp2013J
│               ├── Department.class
│               ├── Employee.class
│               ├── EmployeeDAO.class
│               ├── JDBCTool.class
│               ├── User.class
│               └── UserDAO.class
└── WebContent
    ├── css
    │   └── loginstyle.css
    ├── employeeList.jsp
    ├── example.jsp
    ├── footer.html
    ├── index.jsp
    ├── login.jsp
    ├── META-INF
    │   └── MANIFEST.MF
    ├── updateEmployee.jsp
    └── WEB-INF
        ├── classes
        │   └── ie
        │       └── ucd
        │           └── comp2013J
        │               ├── Department.class
        │               ├── Employee.class
        │               ├── EmployeeDAO.class
        │               ├── JDBCTool.class
        │               ├── User.class
        │               └── UserDAO.class
        └── lib
            └── mysql-connector-java-8.0.15.jar

You should move the compiled classes(with directories) in target folder to WEB-INF/class folder Here is a sample Makefile:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
web-ref: build # web-refresh
mkdir -p ./WebContent/WEB-INF/classes
rm -rf ./WebContent/WEB-INF/classes/*
cp -r $(BUILD_DIR)/* ./WebContent/WEB-INF/classes/
sudo rm -rf /var/lib/tomcat10/webapps/pokemon-gallery/
sudo cp -r ./WebContent/ /var/lib/tomcat10/webapps/pokemon-gallery/

web-start:
sudo /usr/share/tomcat10/bin/startup.sh

web-stop:
sudo /usr/share/tomcat10/bin/shutdown.sh

web-open:
xdg-open "http://localhost:8080/pokemon-gallery/"

web-open-manager:
xdg-open "http://localhost:8080/manager/html"

Run your project

Add your project to tomcat application paths, there are three measures to achieve this:

  1. through tomcat web interface http://localhost:8080/manager/html In Deploy -> Deploy directory or WAR file located on server section, you should fill the blanks of Context Path and WAR or Directory path, which are the relative path of URL and the actual project web content path respectively.
  2. use configuration file: follow /etc/tomcatn/Catalina/localhost/whatShouldFollowLocalhost.xml - ArchWiki
  3. (Recommend: suitable for refresh) copy your web application folder under the tomcat's default webapp folder `/var/lib/tomcat10/webapps` the name under webapp folder is the relative URL path for your application. as shown in the Makefile:

    1
    2
    
    sudo rm -rf /var/lib/tomcat10/webapps/pokemon-gallery/
    sudo cp -r ./WebContent/ /var/lib/tomcat10/webapps/pokemon-gallery/

    It's even better to execute command sudo chmod -R 777 /var/lib/tomcat10/webapps before, so you can remove the sudo prefix in the above commands (not in production environment).