LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

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

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/www.easicasino.com <--- 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: -

Code:
<?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" />

        <GlobalNamingResources>
                <Resource name="UserDatabase" auth="Container"
                type="org.apache.catalina.UserDatabase"
                description="User database that can be updated and saved"
                factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                pathname="conf/tomcat-users.xml" />
        </GlobalNamingResources>

        <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"/>
                        </Realm>

                        <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>
                        <Host name="www.easicasino.com" debug="0" appBase="webapps/www.easicasino.com" unpackWARs="true" autoDeploy="true">
                                <Logger className="org.apache.catalina.logger.FileLogger" directory="logs"  prefix="www.easicasino.com\_log." suffix=".txt" timestamp="true"/>
                                <Alias>easicasino.com</Alias>
                        </Host>
                </Engine>
        </Service>
</Server>
Under $CATALINA_HOME/conf/Catalina/localhost/ROOT.xml I have: -

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

Code:
<?xml version='1.0' encoding='utf-8'?>
<Context displayName="$host" docBase="" path="" workDir="work/Catalina/www.easicasino.com/_">
</Context>
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: -

Code:
package uk.co.f1x2games;

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: -

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

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


An error occurred at line: 10 in the jsp file: /index.jsp
uk.co.f1x2games.PrintString cannot be resolved to a type
7: <p>This virtual server DEFAULT is not yet configured.</p>
8: <p>
9: <%
10: uk.co.f1x2games.PrintString myPrintString = new uk.co.f1x2games.PrintString();
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
cheesus
Member
 
Registered: Jan 2005
Location: Munich, Germany
Distribution: SuSE
Posts: 182

Rep: Reputation: 25
Question

try
$CATALINA_HOME/webapps/www.easicasino.com/WEB-INF/classes/uk/co/f1x2games/PrintString.class
as the class file location.
(you can't use the classes of one webapp (localhost) in another (www.easicasino.com))

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
http://www.javaworld.com/javaworld/j...-1020-ant.html

Cheers, Tom.
 
  


Reply

Tags
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
Trackbacks are Off
Pingbacks are On
Refbacks are 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


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

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