Lab 1 - Running Tomcat on Linux
Step 1 - "Install" Tomcat
-
Download the Tomcat file to your computer. Then copy the
tomcat.tar.gz
file to projects directory. (tomcat.tar.gz) -
Now we get to practice with a couple unix commands to move the file and extract it.
-
First let's determine where your home directory is located.
eval echo ~$USER
-
Then, we'll move the file to the the home directory
Home Directory Move Command If your home directory is /home
sudo mv tomcat.tar.gz ../../home
If your home directory is /home/vscode
sudo mv tomcat.tar.gz ../../home/vscode
-
Navigate to your home directory:
Home Directory Navigate Command If your home directory is /home
cd ../../home
If your home directory is /home/vscode
cd ../../home/vscode
-
What's in the home directory? Let's see:
ls -al
You should see the
tomcat.tar.gz
file in the list of items.-rw-rw-rw- 1 vscode vscode 9541920 Dec 28 15:51 tomcat.tar.gz
-
Next, extract (unzip):
sudo tar -xvf tomcat.tar.gz
-
What did that do? Use
ls -al
. You should see the extractedtomcat
directory.drwxr-xr-x 9 vscode vscode 4096 Sep 26 2016 tomcat -rw-rw-rw- 1 vscode vscode 9541920 Dec 28 15:51 tomcat.tar.gz
-
Inside that tomcat directory is the web server. We'll examine that more later. For now, return to your projects directory:
cd ../../workspaces/YOUR_PROJECT_DIRECTORY/
-
Step 2 - Confirm directory structure
If you haven’t already, confirm your projects directory matches the structure below.
Step 3 - Download additional files
-
Download this file and place it in your new projects/config directory. (web.xml download)
-
Download these files and place them in your projects/lib directory.
Step 4 - Run Tomcat!
-
Open a terminal window and navigate to your projects directory.
-
Launch Tomcat with this command:
$ ant tcup
You should see this output:
@pawaitemadisoncollege ➜ /workspaces/codespacesSpringPrep (master) $ ant tcup Buildfile: /workspaces/codespacesSpringPrep/build.xml tcup: [exec] Tomcat started. BUILD SUCCESSFUL Total time: 1 second
-
At the bottom of your codespace window, click on the PORTS tab. Find the row that starts with Port 8080 and click on the "world" icon to open that port in the browser.
-
Download TrivialServlet.java (Right-click and Save Link As...) and place it in your
projects/src/java112/project2
directory: -
Compile the sample class and deploy your first java web app using this command:
$ ant deploy
-
If this compiles, builds, and deploys your app, you should see something like this and then proceed to the next step.
Buildfile: /home/student/projects/build.xml clean: [delete] Deleting directory /home/student/projects/build [delete] Deleting directory /home/student/projects/dist init: [mkdir] Created dir: /home/student/projects/build [mkdir] Created dir: /home/student/projects/build/classes [mkdir] Created dir: /home/student/projects/dist [mkdir] Created dir: /home/student/projects/build/WEB-INF [mkdir] Created dir: /home/student/projects/build/META-INF [mkdir] Created dir: /home/student/projects/build/WEB-INF/classes [mkdir] Created dir: /home/student/projects/build/WEB-INF/lib compile_web: [javac] Compiling 1 source file to /home/student/projects/build/WEB-INF/classes build_web: [copy] Copying 1 file to /home/student/projects/build/WEB-INF/classes [copy] Copied 1 empty directory to 1 empty directory under /home/student/projects/build/images dist: [war] Building war: /home/student/projects/dist/java112.war deploy: [copy] Copying 1 file to /home/student/tomcat/webapps BUILD SUCCESSFUL
-
Access your forwarded port in the browser, append java112/trivial and hit enter.
-
If you get this web page then you’re done! If you get an error then we start debugging.
Step 5 - Add Tomcat Directory to Explorer
-
Go to the Command Palette, by opening the VSCode menu > View > Command Palette...
-
Type add in the textbox and look for the Workspaces: Add Folder to Workspace... option. You may need to scroll down to find it!
-
Delete the forward slash at the end of /workspaces/ to bring up all folders.
-
Navigate to the tomcat folder and click OK. The tomcat folder will then appear in your Explorer panel.
-
Save your workspace so the tomcat folder will appear in your Explorer panel every time you open codespaces. Navigate back to the hamburger menu and choose
File > Save Workspace As...
Click OK.
Screenshots
To receive credit for this lab save a screenshot in the projects/screenshots/week5
directory.
- Find the code in
TrivialServlet.java
that outputs "TrivialServlet Here!" and update that text to make it uniquely yours. Redeploy and view the servlet in your browser to see your changes. lab1-servlet.png
: The updated servlet running in the browser.
Submit Weekly Labs
- Add, commit, and push!
- Verify all work, including screenshots are visible in GitHub.
- Create a new issue in GitHub: "Week 5 ready for review".
-
Copy the below text and paste it into the "Add a description" textarea. Answer the reflection questions in the space provided.
@kkschumacher #### How are you doing? **Are you encountering any issues preventing you from completing this week's assignments? What can I do to better support you this week?** #### What did you find particularly enlightening this week? #### What challenges (if any) did you encounter in your learning this week? #### What questions (if any) do you have about the material covered this week?
-
Click "Submit new issue"
Rubric
All of the following must be satisfied to achieve a "Met" status
- Screenshot clearly shows the TrivialServlet running in the browser.
- Issue created correctly with thoughtful answers to the reflection questions.