martes, 31 de marzo de 2009

Developing and debugging web applications in eclipse and tomcat

Point tomcat to our web applications sources and debug them in eclipse


Ok this is my situation. I like to program my java web app applications inside some ide like eclipse or netbeans and test them in tomcat. The idea is that tomcat take its resources directly from the eclipse workspace so just saving a file (like a jsp, .java, etc) will instantly apply the changes. Also we will be able to debug our web application java code.

Personally, I like to have my tomcat clean and under control, so I am not a fan of "web development tools" that came with these IDEs.

So, the main idea is for one side, having one project in the IDE with the entire web application resources (java, jsp, xml) and for the other side we will work with a tomcat which have defined a web application that points directly to the eclipse project resources. When we finnish, we will be able to:
  • Have all our web application in one eclipse project.
  • Simply saving modified .java or .jsp resources will impact inmediately the changes in a running application.
  • Debug java code inside eclipse while the web application is running, both in .java and .jsp files.
I will explain how to configure the web applications project inside the eclipse ide.

1) Create an eclipse java project. I suppose you will have one or more java source folders with your application logic, persistence classes, etc.

2) Define a directory for your webapp. Inside the created eclipse project define a directory that will contain exactly the files needed by your webapp application (the files that will be stored in $TOMCAT/webapp/$YOUR_WEBAPP_NAME). This means that your .jsps, WEB-INF/web.xml, WEB-INF/classes, META-INF/ will be here. Later, we will point tomcat to this directory so it will read the resources stored in this.

In my little application I named it /html/ and need to create /html/WEB-INF/web.xml, /html/classes.

3) Output .class files to your webapp dir. We must tell eclipse to put all .class generated files to /html/WEB-INF/classes. For this you have to, in each of your source folders, right click the source folder -> Build bath -> Configure output folder, choose "Specific output folder..." and enter html/WEB-INF/classes.

4) Point tomcat to the project resources. All we need now is to create a tomcat web application that points to our $ECLIPSE_PROJECT/html directory. The best way I found in Tomcat (5.x and 6.x) for doing this is creating the file $TOMCAT/conf/$ENGINENAME/$HOSTNAME/$YOUR_WEBAPP_NAME.xml with the following content:

docBase="$ECLIPSE_PROJECT/html">

in my example I had to create the file C:\apache-tomcat-5.5.27\conf\Catalina\localhost\fileIndexer.xml
with the following content:


docBase="C:\dev\workspace\fileIndexer\html">

If your application needs it, more information can be added to this context file.

5) Libraries. You will have to put all yout java libraries (.jar) in /html/WEB-INF/lib directory for making them available to the tomcat web app.

6) java compiler. We rest only one thing to do and is to be sure that tomcat and eclipse are using the same jre, and that eclipse is generating the propert version .class files. Tomcat uses the jre defined by the environment variable JAVA_HOME and prints to the console which jre is using like:

Using JRE_HOME: C:\Java\jdk1.5.0_15

So one thing we can do is, in eclipse Window->preferences->java->Installed JREs make sure to select the same jre tomcat's using and in Window->preferences->java->Compiler choose a java compliance level supported by that jre.

7) debuggin java in eclipse. Basically we will configure eclipse so tomcat is launched as a eclipse application. In eclipse go to : Run->"Debug configurations..." (or "Open debug dialog..." in 3.3 and previous eclipse versions). There create a new java application launcher, name it appropiately, and in the Main tab select your eclipse project and specify "org.apache.catalina.startup.Bootstrap" as Main class:

Now, in "Arguments" write "start" in Program arguments and something like the following (change it according to your installation):

-Dcatalina.home="C:\apache-tomcat-5.5.27" -Djava.endorsed.dirs="C:\apache-tomcat-5.5.27\common\endorsed" -Dcatalina.base="C:\apache-tomcat-5.5.27"
-Djava.io.tmpdir="C:\apache-tomcat-5.5.27"

Now, "add the external Jar" $TOMCAT/bin/bootstrap.jar in User entries, like in:



and last, in "Source" tab add your java project. Click in "Apply" to save and click "debug" for launching tomcat in debug mode.

Breakpoints in your .java files, or even in you .jsp's java scriptlets will pause the web user requests and open the debug perspective. Try for example, adding a breakpoint in some java code of one of yours jsps, "debug as" your tomcat using the created eclipse java app launch configuration, point the browser to the later jsp and eclipse must pause the thread in debug perspective:

26 comentarios:

Anónimo dijo...

cum dating http://loveepicentre.com/map.php dating revealer

Anónimo dijo...

I go to see day-to-day some web sites and sites to read articles or reviews,
but this website provides feature based articles.


Here is my website combinations

Anónimo dijo...

Thanks very nice blog!

Here is my blog - see more

Anónimo dijo...

I blog frequently and I really thank you for your information.
This article has truly peaked my interest. I will bookmark your site and keep checking for new details about
once a week. I subscribed to your RSS feed as well.


Feel free to surf to my blog :: Email Console

Anónimo dijo...

You really make it seem so easy with your presentation but I find this topic to be
really something which I think I would never understand.
It seems too complex and very broad for me. I am looking forward for your
next post, I will try to get the hang of it!

Here is my homepage more

Anónimo dijo...

Hey I know this is off topic but I was wondering if you knew of
any widgets I could add to my blog that automatically tweet my newest twitter updates.

I've been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

My weblog simply click the next web page - free-press-release-wire.com

Anónimo dijo...

Do you have a spam issue on this site; I also am a blogger,
and I was curious about your situation; we have developed some nice methods and we are looking to trade solutions with other folks, be sure
to shoot me an e-mail if interested.

Feel free to surf to my homepage; how to file for bankruptcy in florida

Anónimo dijo...

I do not know whether it's just me or if everybody else encountering problems with your blog. It appears like some of the written text on your posts are running off the screen. Can someone else please provide feedback and let me know if this is happening to them as well? This could be a issue with my internet browser because I've had this happen before.
Kudos

Take a look at my web site :: visit Website

Anónimo dijo...

Great blog here! Also your site loads up very fast! What web host are you using?
Can I get your affiliate link to your host? I wish my web site loaded up as fast as yours lol

Here is my webpage: visit the up coming document

Anónimo dijo...

[url=http://englandpharmacy.co.uk/products/avodart.htm][img]http://onlinemedistore.com/7.jpg[/img][/url]
columbus regional ambulatory care pharmacy http://englandpharmacy.co.uk/products/synthroid.htm steroidology pharmacy sources [url=http://englandpharmacy.co.uk/products/biaxin.htm]medicine pharmacy synamox 500mg[/url]
new jersey pharmacy regulation dispense http://englandpharmacy.co.uk/products/himplasia.htm keystone pharmacy purchasing alliance [url=http://englandpharmacy.co.uk/products/cialis.htm]cialis[/url]
safeway pharmacy technican pay http://englandpharmacy.co.uk/products/retin-a-0-05-.htm top pharmacy school [url=http://englandpharmacy.co.uk/products/pepcid.htm]acs pharmacy[/url]
harding rd pharmacy springfield oh http://englandpharmacy.co.uk/products/zebeta.htm pharmacy schools in missouri [url=http://englandpharmacy.co.uk/products/zelnorm.htm]zelnorm[/url]

Anónimo dijo...

Keep on writing, great job!

Look into my page ... see more

Anónimo dijo...

These are really wonderful ideas in on the topic of blogging.
You have touched some nice points here. Any way keep up wrinting.


Here is my web page; that guy

Anónimo dijo...

Hello there! Do you use Twitter? I'd like to follow you if that would be okay. I'm definitely enjoying your blog and look forward to new posts.


My blog post; http://pornharvest.com/index.php?q=Asian+Porn+Online&f=a&p=a

Anónimo dijo...

Wow, awesome blog layout! How long have you been blogging for?
you made blogging look easy. The overall look of your site
is fantastic, as well as the content!

Also visit my web blog - click here

Anónimo dijo...

Excellent site. A lot of useful information here.

I'm sending it to a few pals ans also sharing in delicious. And of course, thank you to your sweat!

Feel free to visit my site :: http://nucuoivn.net/vshare/GlennGUYN

Anónimo dijo...

Can I simply say what a relief to discover someone
that really knows what they are discussing online.
You definitely know how to bring an issue to light and make it important.
More and more people really need to read this and understand this side of the story.
I was surprised that you aren't more popular given that you certainly possess the gift.

Stop by my blog: 1

Anónimo dijo...

I am now not positive where you're getting your info, but great topic. I must spend a while learning more or understanding more. Thank you for excellent info I was in search of this info for my mission.

Also visit my homepage http://wlzn.org/blogs/user/LeonardoWa

Anónimo dijo...

gerber software pcb download free http://downloadoemsoftware.co.uk/product-36963/TeraByte-Unlimited-Image-For-Windows-2-6 windows mobile 2005 software [url=http://downloadoemsoftware.co.uk/product-36736/Native-Instruments-Traktor-Pro-2-2-0]bluetooth networking software download[/url] blackberry bold streaming audio software
[url=http://downloadoemsoftware.co.uk/category-15/Special-Offer]Special Offer - Software Store[/url] activesync h4100 software download
[url=http://downloadoemsoftware.co.uk/product-37092/Mask-My-IP-2-2][img]http://buyoem.co.uk/image/5.gif[/img][/url]

Anónimo dijo...

Peculiar article, totally what I wanted to find.

my website: Email Console

Anónimo dijo...

Thanks on your marvelous posting! I definitely enjoyed reading it, you
could be a great author.I will ensure that I bookmark your blog and
will eventually come back very soon. I want to encourage continue your great writing,
have a nice evening!

Feel free to visit my website - lesbian strap on fun

Anónimo dijo...

Yes! Finally something about economic stimulus package.

Look into my homepage - Youtube.com

Anónimo dijo...

Link exchange is nothing else however it is just placing
the other person's weblog link on your page at appropriate place and other person will also do same in support of you.

My webpage :: psn Code generator

Anónimo dijo...

Hey! Quick question that's totally off topic. Do you know how to make your site mobile friendly? My web site looks weird when viewing from my iphone4. I'm trying to find a template or
plugin that might be able to correct this problem.
If you have any suggestions, please share. Cheers!

My web site; microsoft Office Gratuit

Anónimo dijo...

Thank you, I've just been searching for info approximately this topic for a while and yours is the best I have found out so far. However, what concerning the conclusion? Are you sure about the supply?

Also visit my blog :: Free Psn Codes

Anónimo dijo...

This post is worth everyone's attention. Where can I find out more?

Look at my web-site ... dressed like a slut

Anónimo dijo...

Aw, this was a very good post. Spending some time and actual effort
to generate a top notch article… but what can I say… I put things off a lot
and never manage to get nearly anything done.

my site the nubiles angellina