"JGH" <> wrote in message
news:cu8d8b$50$...
>I created some java classes on a tomcat server. Now I want to use them in a
> jsp page. I copied the .class files to $CATALINA_HOME/webapps/ROOT/WEB-
> INF/classes/ and was able to access them.
>
> However, the server doesn't seem to notice if I make a change to one of the
> .class files. I have to make a change to the .jsp page that uses the
> class. I've gotten in the habit of adding a space and then deleting it and
> then saving the source code for the .jsp page each time I make a change to
> one of the .java files and recompile to create a new .class file.
>
> I tried putting the .java files in the .../classes directory because I had
> read that this would work. But I got an error message that said my classes
> were missing.
No. Tomcat will not compile your classes for you.
> Besides, I don't want to put my source code in the tomcat space. When I'm
> done with it, maybe. But I'm still working on it and I want it in a subdir
> of my own home directory.
>
> So I guess this is a 2 part question: How do you manage your source code?
Part of my typical directory structure looks like:
src
java
webapp
"java" is my .java files, and "webapp" holds JSPs, WEB-INF contents besides
classes and JARS, etc.
> And how do I get tomcat to recognize that I've changed a .class file?
First, from what you said above, it sounds like you're using the default context
to run your webapp. I don't know anything about configuring that. I don't know
how similar it is to configuring other contexts either. For a normal context, it
depends somewhat on what version of Tomcat you're running. Ultimately, in any
(recent) version, there is a "Context" element in an XML configuration file
somewhere, either in $CATALINA_HOME/conf/server.xml for Tomcat 4 (and 5 if going
against Jakarta's suggestion) or in an individual, smaller XML file in
$CATALINA_HOME/conf/Catalina/localhost, assuming a default setup. A basic
Context element looks like this:
<Context docBase="C:\Projects\publicExamples\target" path="examples">
</Context>
For Tomcat 5, that would go in a file named "examples.xml", and I believe the
"path" attribute is optional and it will take its name from the file, but I
don't know that for sure. What this does is map
http://localhost:8080/examples
to the folder "C:\Projects\publicExamples\target". "examples" is your context.
Now, to answer your question, add an attribute to your Context element:
reloadable="true"
That causes Tomcat to watch for changes to class files, web.xml, and
META-INF/context.xml. It will be the main thread (I think) monitoring for
changes when it has time. If you want to spawn a new thread devoted to watching
for changes, add another attribute:
backgroundProcessorDelay="2"
That causes the new thread to check for changes every 2 seconds. For more
details on setting up contexts and Tomcat in general, see:
http://jakarta.apache.org/tomcat/index.html
Click your Tomcat version on the left under "Documentation", then on the next
page click "Tomcat Configuration" under "Reference".