Tomcat Setup
Tomcat Setup
cgi
Download Ant (binary?) from https://ant.apache.org/
6. $CATALINA_HOME/bin/shutdown.sh
https://www.jetbrains.com/help/idea/2019.1/dependencies.html
This panel opens with CTRL-SHIFT-ALT-S. the '+' is a little hidden. look at the
right.
The same panel has the code output path.
To build the project, hit the Build button.
1. in "home" directory *of webapp* - *.html, *.jsp etc i.e html and jsp files
along with css, javascript, image etc files *that must be visible to the client
browser*
2. /WEB-INF/web.xml - an xml file that describes the servlets and other
components of your application + initialization parameters (??) + container managed
security constraints. (?? I think this is basically a (per application?/per tomcat
instance?) meta data file, 'describing' things)
3. /WEB-INF/classes - application specific classes, both servlets and non
servlets which are *not combined into jars*. The directory structure has to reflect
the name spacing. i.e, a class named com.mycompany.myPackage.myServlet will be in a
directory /WEB-INF/classes/com/mycompany/myPackage/myServlet.class
4. /WEB-INF/lib contains jar files that contain java classes your application
requires. can include, for example, jdbc drivers.
Note: the above is the 'unpacked' directory structure. These can also be packed
into a WAR archive for distribution.
many CLASSPATH issues with TomCat. How to understand and fix them.
This problem is actually easy to fix. Tomcat documentation assumes that most people
always pick "the easiest" way of doing things.
1. Tomcat does not resolve CLASSPATH the same way as java programs
Tomcat aims to be selfcontained, to standardize the configuration and deployment of
webapps, while limiting access to libraries for security reasons. So Tomcat start
scripts *ignore CLASSPATH variable*, and generate their own classpaths when they
create Tomcat's "system" classloader.
the Bootstrap classloader contains the basic runtime classes provided by the JVM,
pivoting off JAVA_HOME
the System classloader is built from the following repositories.
1. $CATALINA_HOME/bin/bootstrap.jar - contains the main() method of Tomcat,
2. $CATALINA_HOME/bin/tomcat-juli.jar - logging implementation. juli =
java.util.logging implementation
3. $CATALINA_HOME/bin/common-daemons.jar - This jar is *not* present in the
CLASSPATH built by the catalina.sh scripts, but is referenced from the manifest
file of bootstrap.jar
the Common classloader contains(?) additional classes that are made visible to
*both* tomcat *and* *all* web applications.
the webappX classloaders - a classloader is created for each web app that is
deployed in a single Tomcat instance.
all unpacked classes in /WEB-INF/classes directory of
your webapp, plus classes and resources in jar files under the WEB-INF/lib
directory of your web application and made visible to *each* web application, but
not to others
To deploy a MyServlet.java to a tomcat and access it via the browser you should
1. create a directory for your web app with a WEB-INF subdirectory
2. create a classes directory and put MyServlet.class there
3. configure web.xml
4. configure conf.xml ?? something something , basically configure tomcat
3. configure web.xml
From http://tutorials.jenkov.com/java-servlets/web-xml.html
Sample web.xml (just enough for HelloWorld servlet. Expand later with init
parameters from web.xml etc)
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
....
</servlet>
<servlet-mapping>
.....
</servlet-mapping>
</webapp>
the servlet tag has two subtags, servlet-name and servlet-class, to give
<servlet>
<servlet-name>helloWorldServlet</servletname>
<servlet-class> com.mycompany.HelloWorldServlet<servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloWorldServlet</servlet-name> note this links to name above
that maps to a classe
<url-pattern>*/html</url-pattern> note: all urls ending in *.html is sent to
the servlet.
</servlet-mapping>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>controlServlet</servlet-name>
<servlet-class>com.jenkov.butterfly.ControlServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>controlServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>