Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tomcat configuration for development 2

Status
Not open for further replies.

xor

Programmer
Jan 7, 2001
71
0
0
NZ
I am writing jsp pages and serving them with tomcat, I trying to apply the fusebox methodology (I'm used to using it with coldfusion, and I'm trying to adapt it to jsp), so I've got a switch statement in my index.jsp page which looks at a url variable and decides which content page to load. The problem is that if I make changes to a content page I am working on I have found that I must also make a change to the index.jsp page and save that in order to get tomcat to recompile the jsp page that I am really working on. Is there anyway to get tomcat to recompile pages every time you reload a page in the browser? It would make my development cycle so much easier.

TIA,
Donna
 
So you are including the page into your base JSP? First off this is probably not the best design. A better design would be to go with a straight MVC pattern and have a standard Servlet direct traffic to a multitude of JSP pages. Secondly, Tomcat has a problem with detecting changes within an included page and there is no solution that I know that will fix it. A work around is to write a script to blow away the compiled JSP classes after every change that you make. This will effectively forced EVERY JSP to recompile.

Other Web Container don't have this problem so you might also consider using a Web Container like Resin ( I highly recommend that you reconsider you design though.
 
You are only concerned with this during development, right? So what I did was use Ant's touch functionality to 'touch' every jsp page in the directory where my jsp pages are. My solution hase two files touchjsp.xml and touchjsp.bat. Everytime I make a change to a jsp fragment--that is in a jsp page via include directive--I touch all my jsp files so they will recompile upon being called. Just type in 'touchjsp' at the DOS prompt.

Here is my code:

touchjsp.xml --------------------------------------------------
<project name=&quot;Touch jsp files&quot; default=&quot;main&quot; basedir=&quot;.&quot;>
<target name=&quot;main&quot;>
<touch>
<fileset dir=&quot;${target_dir}&quot;>
<include name=&quot;*.jsp&quot;/>
</fileset>
</touch>
</target>
</project>

touchjsp.bat --------------------------------------------------
@echo off
call addant
pushd d:\bin
call ant -quiet -buildfile touchjsp.xml -Dtarget_dir=<put full path to jsp files here>
popd

------------------------------------------------------------
PS my addant.bat sets classpath and path as needed for Ant to work.
 
Thanks pfist, that's great, i will give it a go!

Thanks also wushutwist for your comments. I am an experienced ColdFusion developer who also knows java, but I am just starting out with jsp/java servlets. jsp seemed much quicker for me to learn, especially with my strong CF background, but I do really want to have much more separation between code and content than I have been managing with jsp. This is just a personal project that I am working on, jsp seemed the fastest way for me to get it finished and to start learning about jsp/servlets, but then I planned to rework it using MVC and a better methodology for content/code separation anyway.

Your comment &quot;A better design would be to go with a straight MVC pattern and have a standard Servlet direct traffic to a multitude of JSP pages.&quot; is good, it gives me a starting point. I will also try Resin and pfist's solution.

Can anyone recommend a good book/website on jsp/servlets that has a strong focus on the MVC pattern? I've printed the sun tutorial on servlets, and I'm working my way through that, but I'd like something that emphasises good design principles a little more as well.

Thanks :D
 
There is a way for Tomcat to recompile your classes.i did it for my servlets. In server.xml go to Context
<!-- Tomcat Root Context -->

<Context path=&quot;&quot; docBase=&quot;ROOT&quot; debug=&quot;0&quot; />

<Context path=&quot;/applicationDir&quot; docBase=&quot;yourdirname&quot; debug=&quot;0&quot; reloadable=&quot;true&quot; crossContext=&quot;true&quot;/>
That is it.
So every time you compile.. you dont have to restart the tomcat server.
chao
vaneet
 
One year later and I'm running into this same issue with Fusebox for J2EE. Did you manage to solve it at all? Even with a script to touch all the files (thanks pfist), it doesn't solve the issue for production. Basically no matter what my fuseaction is in the URL it doesn't matter as it still includes the last page viewed. Miles

Those Micros~1 guys sure know what they doing!
 
I cannot get my servlets to run. i did the whole servlet-mapping thing with the invoker, and still it's giving me a 404 Error. The servlet i am trying to run is in the
ROOT/WEB-INF/classes folder. I also have activated the ROOT context. What should i do?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top