Tomcat Organization Deploying applications
Confusion Like a web server Root locations are from a defined directory location In addition… from that point applications have a specific directory expectation. First recall how a web server works Web URL: Document Root: /var/lib/http Real file location: /var/lib/http/abc/def/home.html
Confusion (more) In a tomcat server, applications have a similar root From that point some things are obvious, but most are not Applications (servlets etc) have a required organization below that First the general root Then the specific structure of the application
General root application location $CATALINA_HOME/webapps Example: if installed in /var/lib/tomcat5 Application root is at /var/lib/tomcat5/webapps Activity: Try to create a simple web page (html). Place it in the webapps directory. Try to access it through a browser. (it won’t work … there’s more)
General root application location (more) If you put your file in /var/lib/tomcat5/webapps/myfile.html And tried to access it through Experience says that this is the root and that the browser should Be able to find it. But the “root” directory actually is in another Location and named ROOT. (see the next slide)
webapps directory / usr/ share/ tomcat5/ webapps/ ROOT/ app1dir/ app2dir/ This is where the html file should go Then will find it (/var/lib/tomcat5/webapps/ROOT/myfile.html) TRY IT!
webapps directory / usr/ share/ tomcat5/ webapps/ ROOT/ app1dir/ app2dir/ So what are these? … There are application directories. Let’s see what a typical application directory looks like.
An application directory app1dir/ html files etc. WEB-INF/ classes/ lib/ web.xml These files can not be accessed directly by a user URL. Only indirectly as you will see.
Html files in an application directory app1dir/ html files etc. WEB-INF/ classes/ lib/ web.xml Various html files, images etc. E.g. j.html in appdir1 would be accessed as NOTE: ROOT is not in the URL but app1dir is! webapps/ ROOT/
Servlets in the application app1dir/ html files etc. WEB-INF/ classes/ lib/ web.xml Any servlet in app1dir is defined in web.xml. (more later) The class file for a servlet in app1dir is in classes. webapps/
app1dir/ html files etc. WEB-INF/ classes/ lib/ web.xml Servlets in the application webapps/ HelloWorld.class Accessed with URL (don’t try it yet!)
web.xml file <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" " My 611 Hello World Application This is a Sample Hello World Application used simply to test deployment of my own application. HelloWorldExample611 One servlet in the application HelloWorldExample611 HelloWorldExample611 /HelloWorldExample optional must change
Special issues w/linux tomcat app1dir/ html files etc. WEB-INF/ classes/ lib/ web.xml listeners ContextListener.class SessionListener.class I have not yet determined why it is necessary. Logs indicated this to Be a problem, even though web.xml doesn’t indicate it to be necessary. Copied from servlet directory.
Create your own There is a 611 user established for development. Create a subdirectory with your name to do your own development. Create and compile a simple HelloYourname servlet. Name the web application YourName “su” and log in as root Set up the directory structure and copy files as indicated Set permissions to allow read for group “tomcat chgrp –R tomcat * chmod –R 775 * will recursively set permissions
Create your own (more) Now to make the server aware of your application Launch the base page ( :8080) Access Tomcat Manager link You should see your application listed and started. If necessary, go to /etc/rc.d/init.d and run tomcat5 restart (it should not be necessary) Now try accessing via :8080/yourapp/yourservlet