How to copy a class file (compiled servlet) to tomcat

Core Servlets and Java Server Pages tell me:

Once you compile HelloServlet.java, put HelloServlet.class in the appropriate location (usually the WEB-INF/classes directory of your server’s default Web application). […] Then, access the servlet with the URL http://host/servlet/HelloServlet […

 

and:

 

Tomcat directory for Java .class files.

install_dir/webapps/ROOT/WEB-INF/classes (Note: in many Tomcat versions, you’ll have to manually create the classes directory.) […] http://localhost/servlet/HelloServlet (or http://localhost:8080/servlet/HelloServlet)

It neglected to say the following:

  1. Set the JAVA_HOME environment variable to point to the location of java. Mine is

    c:\progra~1\java\jdk1.6.0_14

  • Turn on servlet reloading. Edit the file c:\tomcat\conf\context.xml and change the context tag in the file to Context reloadable="true"
  • Enable the invoker servlet. Go to c:\tomcat\conf\web.xml and uncomment the servlet and servlet-mapping elements that map the invoker servlet to /servlet/*.
  • Number Three above is the most important. Just look at the file web.xml and look for the word invoker. It’s in two places, and they are quite far apart from each other. There are loads of other places that have a element so be sure to uncomment the correct one.

    It turns I found this solution by google, and it actually ended up on the author’s site, in case you need more information: http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-5.5.html

    Advertisements

    About SunKing2

    Former web developer, guitar player, started Piano 2012 -yes still doing it! Recovery, sobriety, mental health advocate.
    This entry was posted in Servlets, Tomcat. Bookmark the permalink.

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s