Installing a virtual host outside of Tomcat 8 webapps

To not have to install websites within tomcatX/webapps do the following. I chose to install connected to localhost.  The name for this site is fileSystem so:

  • create a fileSystem.xml file for this app and place it in %TOMCAT_HOME%\conf\Catalina\localhost
  • the contents of fileSystem.xml is
<Context displayName="fileSystem" 
     docBase="/home/roye/tomcat/fileSystem"
     path="/fileSystem"
     reloadable="true" />
  • docBase contains the traditional directory structure
  • stop and start, or reload tomcat
  • the resulting URL is http://localhost:8080/fileSystem
  • to link to servlets within a html page the link is e.g.

Tomcat installation and setup notes

Introduction

A good link to use – https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-16-04 However, this installs Tomcat for public exposure.

I chose to install it in my personal account. The primary reason was to put it in a non-sudo directory so it would be easier to work with.  It is running on my personal laptop with no other users. Another reason was I wanted to easily run my Servlet in my local directory for testing and mirroring sites that might use them.

The structure I’m using:

~/tomcat

tomcat* (this entire tomcat install)

‘site n’-webapps

‘site n’-docBase

Steps I used

  1. I did create a tomcat group – sudo groupadd tomcat
  2. I did not create a tomcat user and assign its directory above as `useradd` will not create a user using tomcat8
  3. I created private structure – mkdir tomcat ; mkdir tomcat/tomcat8
  4. I installed tomcat into tomcat8 – tar xzvf Downloads/apache-tomcat-8.5.27.tar.gz -C /home/roye/tomcat/tomcat8 –strip-components=1
  5. I changed  the group – chgrp -R tomcat tomcat8
  6. I changed – chmod -R g+r conf  ;  chmod -R g+x conf

Website Structure

docBase    WEB-INF        web.xml  <- configures which servlets are used, welcome pages, security 
                 issues        classes  <- a directory containing the servlets and supporting classes. 
                 This is a root classes must be locate below by their package name
                 e.g. com.cnrepperson.test.TestClass.class
            com
                cnrepperson
                    test
                        TestClass.class
    static_content  <- html, php and other content not associated with the site's
                    configuration or servlets

 Setting up Tomcat for remote debugging using Eclipse

Summarized from https://confluence.sakaiproject.org/display/BOOT/Setting+Up+Tomcat+For+Remote+Debugging

We recommend adding this stuff to your startup script so that you are always running tomcat in debug mode.

  1. Open the startup script in (your_tomcat_home)/bin/startup.sh
  2. Add the following lines at the first blank line in the file (around line 8)
    export JPDA_ADDRESS=8000
    export JPDA_TRANSPORT=dt_socket
  3. Change the execute line at the end to include jpda start
    exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"
  4. Run the startup script when starting tomcat to run tomcat in debug mode

Setup up Eclipse

copied from http://starredmediasoft.com/tomcat-configure-remote-debugging/ on eclipse do the following steps:

  1. Select project to debug
  2. Choose “Debug configurations..” on Debug menu
  3. On “Remote Java Application” left menu, click “New Launch Configuration” button
  4. On Connection Type, select “Standard (Socket Attach)” combo item
  5. Type on the listening port (on the above tomcat configuration, was 8000)
  6. Click on Debug and start listening
1 2 3 8