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.
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.
in my example I had to create the file C:\apache-tomcat-5.5.27\conf\Catalina\localhost\fileIndexer.xml
with the following content:
If your application needs it, more information can be added to this context file.
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"
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: