Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 03-11-2011, 05:12 AM   #1
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 394

Rep: Reputation: 61
Unhappy Tomcat 7.0.8 not finding my packaged classes. Please help.

I'm trying to set up Apache Tomcat with virtual hosting. I've used Caucho Resin before but not Tomcat...and I've run into what appears to be (from Google at least) a rather common problem with Tomcat in that any properly packaged classes under WEB-INF of the default virtual host or the named host are not found and Tomcat complains of a class that "cannot be resolved to a type".

I researched this error on Google and the consensus seems to be that: -

- You need properly packaged classes as classes in the default package are no longer allowed. I have done this.

- You need to either fully declare the packaged class to make an instance of it within the JSP or include the via an import statement at the top of the JSP. I have done this.

- In the web.xml for the Tomcat server instance (under $CATALINA_HOME/conf/web.xml) you need to set the servlet mapping for JSPs fork init-param to "true". I have done this also.

Yet the problem persists and I have found no solution. So I can only assume I'm missing something obvious and fundamental. My configuration is as follows: -

I have two virtual hosts - one as the default virtual host and another as a named virtual host.

$CATALINA_HOME/webapps/localhost <--- Default host.
$CATALINA_HOME/webapps/ <--- Named host. The logic being that the URL IP address of the server will hit the default webapp and the URL hostname with hit the named webapp. This appears to work with just JSPs.

My $CATALINA_HOME/conf/server.xml looks like this: -

<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
        <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
        <Listener className="org.apache.catalina.core.JasperListener" />
        <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
        <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
        <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

                <Resource name="UserDatabase" auth="Container"
                description="User database that can be updated and saved"
                pathname="conf/tomcat-users.xml" />

        <Service name="Catalina">
                <Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" />
                <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
                <Engine name="Catalina" defaultHost="localhost">
                        <Realm className="org.apache.catalina.realm.LockOutRealm">
                                <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>

                        <Host name="localhost"  appBase="webapps/localhost" unpackWARs="true" autoDeploy="true">
                                <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                                prefix="localhost_access_log." suffix=".txt"
                                pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false"/>
                        <Host name="" debug="0" appBase="webapps/" unpackWARs="true" autoDeploy="true">
                                <Logger className="org.apache.catalina.logger.FileLogger" directory="logs"  prefix="\_log." suffix=".txt" timestamp="true"/>
Under $CATALINA_HOME/conf/Catalina/localhost/ROOT.xml I have: -

<?xml version='1.0' encoding='utf-8'?>
<Context displayName="localhost" docBase="" path="" workDir="work/Catalina/localhost/_">
and under $CATALINA_HOME/conf/Catalina/ have: -

<?xml version='1.0' encoding='utf-8'?>
<Context displayName="$host" docBase="" path="" workDir="work/Catalina/">
With simple JSPs with no external classes under WEB-INF, this configuration works fine. But as soon as I added a class to the default webapp's index.jsp, Tomcat couldn't compile the index.jsp because it couldn't find the class I was trying to instance.

I created a simple class with one method that simply returns a String. It is held under $CATALINA_HOME/webapps/localhost/WEB-INF/classes/uk/co/f1x2games/PrintString.class and is simply: -


public class PrintString {
        private String theString = "This is a returned string. Wowie.";

        public PrintString() {}

        public String getString() {
                return theString;
Notice that it is in a package. I then added it to the default virtual host's index.jsp like this: -

<%@page language='java' import="*"%>
<title>DEFAULT Not yet configured</title>
<p>This virtual server DEFAULT is not yet configured.</p>
<% myPrintString = new;
The default host's /WEB-INF/web.xml is more or less empty at the moment with: -

<?xml version="1.0" encoding="ISO-8859-1"?>
So when hitting the IP address of the server, Tomcat attempts to compile the index.jsp but cannot because it cannot resolve to a type with the error: -

An error occurred at line: 10 in the jsp file: /index.jsp cannot be resolved to a type
7: <p>This virtual server DEFAULT is not yet configured.</p>
8: <p>
9: <%
10: myPrintString = new;
11: %>
12: </p>
13: </body>

I gather this error is to do with Tomcat not being able to find the class it's trying to instance and the only advice is that given at the top of this post.

What am I missing here? I can't *not* use classes in a webapp....

Help please?

Last edited by arashi256; 03-11-2011 at 05:18 AM.
Old 03-19-2011, 06:19 AM   #2
Registered: Jan 2005
Location: Munich, Germany
Distribution: SuSE
Posts: 184

Rep: Reputation: 25

as the class file location.
(you can't use the classes of one webapp (localhost) in another (

but this is all very confusing.

in the end, you will be better off by using a ant script to build a .war file, like

Cheers, Tom.


cannot resolve, classes, java, tomcat

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Session replication using apache+mod_jk+tomcat(5.5.28-veriosn of tomcat) sreejithp Linux - Server 1 12-24-2010 06:46 AM
Which distro has these packaged in? Networks Linux - Distributions 5 06-12-2007 11:06 PM
OOP (PHP) classes and extended classes ldp Programming 3 03-05-2005 11:45 AM
TOMCAT init script not working on startup -- tomcat 4.x / Mandrake Linux 8.0 jmartinph Mandriva 0 03-08-2004 01:31 AM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:44 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration