As usual, a book follows the original message.

I apologize for the length.

/mde/

--- Original Message ---
From: Karl Schmitt <karlschmitt1...@googlemail.com>
To: Tomcat Users List <users@tomcat.apache.org>
Sent: Sun, April 24, 2011 2:06:25 AM
Subject: Re: Problems deploying a servlet on ubuntu

Thanks Andre,

for answering my call for help,
I tried to answer you questions as best as I could below: 

Tomcat was installed using the synaptic packet management
I just ticked tomcat6 and hit the apply button, and tomcat and all its 
dependencies
were installed and http://locaclhost:8080 started to work,
that was the easy part :-) 

karl@sonoma:/usr/share/tomcat6/bin$ ./version.sh
Using CATALINA_BASE:   /usr/share/tomcat6
Using CATALINA_HOME:   /usr/share/tomcat6
Using CATALINA_TMPDIR: /usr/share/tomcat6/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.6.0-openjdk
Using CLASSPATH:       /usr/share/tomcat6/bin/bootstrap.jar
Server version: Apache Tomcat/6.0.24
Server built:   March 24 2011 1829
Server number:  ...0
OS Name:        Linux
OS Version:     2.6.32-31-generic
Architecture:   i386
JVM Version:    1.6.0_20-b20
JVM Vendor:     Sun Microsystems Inc.
karl@sonoma:/usr/share/tomcat6/bin$ 

karl@sonoma:/usr/share/tomcat6/bin$ echo $JAVA_HOME
/usr/lib/jvm/java-1.6.0-openjdk

karl@sonoma:/usr/share/tomcat6/bin$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.7) (6b20-1.9.7-0ubuntu1~10.04.1)
OpenJDK Client VM (build 19.0-b09, mixed mode, sharing)

My web.xml is located here:
karl@sonoma:/usr/share/tomcat6/webapps/ch1/WEB-INF$ ls
classes  web.xml

My servlet is located here:
karl@sonoma:/usr/share/tomcat6/webapps/ch1/WEB-INF/classes$ ls
Ch1Servlet.class

karl@sonoma:/etc/tomcat6$ ls
Catalina             context.xml         policy.d    tomcat-users.xml
catalina.properties  logging.properties  server.xml  web.xml
karl@sonoma:/etc/tomcat6$ 

---------------------------------------------------------------
My grep for "host" in server.xml:

karl@sonoma:/etc/tomcat6$ grep -A 5 "[Hh]ost" server.xml 
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">         
    --> 
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
--
      <!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true" deployOnStartup="true"
            xmlValidation="false" xmlNamespaceAware="false">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
--
               prefix="localhost_access_log." suffix=".txt" pattern="common" 
resolveHosts="false"/>
        -->

      </Host>
    </Engine>
  </Service>
</Server>
karl@sonoma:/etc/tomcat6$ 
------------------------------------------------------------------------------------



here I will try to attach the whole server.xml file:





On Sat, Apr 23, 2011 at 11:41 AM, André Warnier <a...@ice-sa.com> wrote:


>
Sorry, but I don't know the book.
>So maybe you can tell us some more :
>- how did you install Tomcat ? where did you get it ?
>- what version is it ?
>(go to the "bin" directory of tomcat, and run "./version.sh"; paste the result 
>here)(*)
>- what version is the JVM ?  ("java -version" may tell you, if the above 
>doesn't)
>- can you give us the exact paths where you installed your servlet files ? 
>(the 

>servlet itself and the web.xml file)
>- in the Tomcat "conf" directory (in your case, it may be in /etc/tomcatxx), 
>there is a file "server.xml". In that file, is a <Host> tag, which gives the 
>path for the webapps directory (in the "appBase" attribute). Which is that ?
>
>
>(*) if this is a "packaged" tomcat, this may complain that JAVA_HOME is not 
>set. 
>
> If so, you first have to locate what JAVA_HOME should be set to.  Look then 
> in 

>/etc/init.d/tomcatxx to find out.


--- End Original Message ---

First, a caveat.

I run Fedora, not Ubuntu so your mileage may vary. I also only have the first 
edition of the book, so the instructions may have changed between editions. By 
the way, I like the book (and Head First books in general).

Short version for the impatient:

1. You probably have a permissions problem.

The packaged installation of Tomcat may not have the permissions to
read your web application that you copied into  /usr/share/tomcat6/webapps/ch1. 
You could fix this by doing the appropriate chmod for your system. However, see 
below for a different approach.

2. You are you using OpenJDK

This won't impact you in the short term. However, there have been several 
issues 
reported on the mailing list that have been cleared up by using the Oracle JDK 
and JRE. You can install these with apt-get on Ubuntu.

3. Solution

Install a local copy of Tomcat from tomcat.apache.org in your home directory. 
Use this for development work.

Install Oracle's JDK and JRE. There are several examples on how to do this with 
Ubuntu. Make sure it's your default JDK and JRE.

Longer version:

The packaged version of Tomcat is designed to run as a service, and may not be 
as easy to use for development. Starting and stopping probably requires root 
access, so integration down the road with an IDE such as NetBeans or Eclipse 
will be difficult.

Another issue you may run into is one of permissions. Depending on how you 
copied your Chapter 1 web application into /usr/share/tomcat6/webapps, the 
Tomcat process may not have read permissions on the files, nor execute 
permissions on the directory.

I was able to simulate a 404 on my system by changing ownership of a web 
application, and removing "other" read and execute access.

There have been several issues reported on the mailing list that have been 
traced back to using OpenJDK. It's much safer to install Oracle's JDK and use 
that as your default Java.

Here's a link to one way to install Oracle's JDK / JRE.

http://thilina.gunarathne.org/2011/02/installing-sun-oracle-jdk-6-on-ubuntu.html

Since I don't use Ubuntu, it's probably best to verify this before installing 
on 
you system.

I find the easiest way to do servlet/jsp development work on Linux is the 
following:

1. Install Oracle's JDK and JRE.

This is distribution-specific. I gave one link I found for Ubuntu, but please 
check for your distribution. Make sure that this is your default Java (java 
-version and javac -version).

2. Get a tar.gz copy of the latest Tomcat from tomcat.apache.org

The first edition of the book covers the servlet 2.4 specification, so 
technically 5.5.33 is all that's required.

The second edition of the book covers the servlet 2.5 specification, so 
technically 6.0.32 is all that's required.

That being said Tomcat 7.0.12 should run both 2.4 and 2.5 specification web 
applications just fine. You might as well go for the latest and position 
yourself to learn the 3.0 servlet specifications down the road.

3. Unpack the Tomcat distribution in your home directory somewhere.

I tend to make a separate directory and unpack it there. This makes my home 
directory a bit neater since I have several different Tomcat versions as well 
as 
a few cluster configurations.

4. Follow the instructions on editing tomcat-users.xml

This varies slightly depending on which Tomcat version you're running. Make 
sure 
the users are not commented out.

5. Make sure the system version of Tomcat is stopped.

The easiest way to do development work with your personal copy of Tomcat is to 
stop the system copy of Tomcat. There are ways to run both (involves changing 
some ports, and is not too difficult), but for learning purposes this is 
probably not necessary.

Now you have a standard environment to work with while learning servlets, jsp, 
and web application design patterns. This will make it easier for you to follow 
along in the Head First book. It will also make it easier for you to get help 
from the Tomcat mailing list.

Welcome to Java web application programming.

. . . . just my two cents.

/mde/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to