Debugging Web-application deployed on Tomcat using Eclipse

January 15, 2010

Hello,
This small article will walk you through the steps needed to setup the Eclipse environment for debugging Web application deployed on Tomcat server. I have used Tomcat 6.0.18 and Eclipse Ganymede for this purpose.

  1. Add the following lines in {tomcat.home}/bin/catalina.bat. tomcat.home is your tomcat installation directory.
  2. set JPDA_ADDRESS=1044
    set JPDA_TRANSPORT=dt_socket
  3. Open Eclipse “Debug Configurations” window. Menu Navigation – Run > Debug Configurations…
  4. Add new “Remote Java Application” as below
  5. The “Port” should match to the JPDA_ADDRESS configured above in step #1.
  6. Click “Debug” to start debugging.
  7. Start the Tomcat server using command “catalina jpda run”. This starts Tomcat in debugging mode.
  8. If the “Breakpoint” is encountered while application is being executed, Eclipse will ask you if you want to switch to Debug perspective where you can debug the application using standard debug controls.
  9. There is one nice article on IBM developer works that explains Debugging. Here is one helpful resource to know more about debugging techniques IBM RAD Tutorial .

Hope this helps in setting up a Eclipse Debugger for debugging your applications.  Do let me know if you feel this article needs improvements and your suggestions.

Cheers !

Amit

Advertisements

Setting Connection Pool in Tomcat 6.x

December 7, 2009

Hi,

Recently I was configuring a connection pool for Oracle database on Tomcat server. Hence thought of sharing the same with you all.  I am sure that everyone out there must have done this and found it simple. The reason for posting this is that most of my colleagues missed putting the driver JAR file in the server lib directory which is needed by tomcat to refer the driver classes at the start-up.

  1. Make sure you have the JDBC Drivers placed in the {tomcat.home}/lib directory. For Oracle 10g use ojdbc14_g.jar
  2. Create a file named context.xml in <<yourwebapp>>\WebContent\META-INF directory.
  3. Use Resource element to configure the connection pool as shown below.
  4. Sample context.xml file

    <?xml version="1.0" encoding="UTF-8"?>
    <Context antiResourceLocking="false" privileged="true" cookies="true">
    <Resource name="jdbc/mypool" auth="Container"
    type="javax.sql.DataSource"
    driverClassName="oracle.jdbc.OracleDriver"
    url="jdbc:oracle:thin:@<<host:port>>:<<sid>>"
    username=<<username goes here>>
    password=<<password goes here>>
    maxActive="20" maxIdle="10" maxWait="-1"/>
    </Context>
    
  5. Add the resource reference to the DataSource created in Step#3 to the web-application using web.xml.
  6. Refer the DataSource using “<res-ref-name>” as the JNDI name in your source.
  7. E.g.

    <resource-ref>
    <description>DataSource for Web Application</description>
    <res-ref-name>jdbc/mypool</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    

Hope this helps you setting up the connection pool.

Note: Resource element used to configure the connection pool has lot of configurable properties. Only base minimum properties are used above. For further information on DBCP configuration you can refer DBCP Configuration Parameters