• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

mod_jk and Apache Virtual Hosts

Posts: 1
Mac OS X Tomcat Server Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have set up a virtual host in Apache, which is intended to host and execute all Servlets and JSPs which are located in this vhost directory.

(A snippet of my config-files is on to bottom of this post, because attachments doesn't work yet.)

This setup works fine, BUT the Servlets / JSPs are processed ONLY when they are stored and executed in Tomcat's "webapps" folder.
(When I move the Servlets and/or JSPs to the vhost-directory, I get an error; produced by Tomcat.)

So - WHAT CAN I do that my Servlets and JSPs are stored AND executed in my vhost directory?

Kind regards, Chris

P.S.: I've read a lot of documentations and tried out many different setups before I posted this thread!

Config Snippet:

# httpd.conf

# I've deleted all uncommented tags (#) AND those which seem to be unnecessary (for my setup)


Listen 80


Include conf/mod_jk/httpd-jk.conf


NameVirtualHost *

<VirtualHost *>
      ServerName www.mydomain.com
      DocumentRoot /.../www


<VirtualHost *>
      ServerName servlettest.mydomain.com
      DocumentRoot /.../servlettest

      JKMount /* worker1

# httpd-jk.conf

# I've deleted all uncommented tags (#)

LoadModule jk_module modules/mod_jk.so

<IfModule jk_module>

      JkWorkersFile conf/mod_jk/workers.properties

      JkLogFile logs/mod_jk.log

      JkLogLevel info

      JkShmFile logs/mod_jk.shm

      JkWatchdogInterval 60


#END config snippet
Posts: 20845
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First you need to understand how Enterprise Java webapps are architected.

You cannot simply dump a bunch of files somewhere and expect them to run in Tomcat or for that matter, any other J2EE webapp server. A J2EE webapp is - according to the standard, a bundle of files with specific meanings and relationships, all zipped together in a JAR called a WAR file. Tomcat can deal with unzipped versions of this JAR format as well (called "exploded WARs"), but the actual j2EE standard only specifies them in zipped form.

As part of this standard, a web application context is defined. Since a J2EE can host many apps - even without virtual hosting - each webapp has a context path that's part of the URLS that get routed to that particular webapp. In fact, it's the context path that determines which app the URL is routed to.

Furthermore, to execute servlets, you have to map the servlet to a URL pattern as well, which is something you do by coding the mapping in the WEB-INF/web.xml file of the WAY. Very, very old Tomcat releases didn't require this, but it was a horrible security feature and J2EE is big on security.

You don't need to define your WAR - or its directories - to Apache httpd at all, however. Just set up an Apache virtual host and code the appropriate mod_jk or mod_proxy directives in that virtual host definition. Apache will then forward all the matching URLs to Tomcat and Tomcat can take care of the rest. As long as you've deployed your webapp correctly inside Tomcat.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!