Don’t use Eclipse’s web viewer for Cobertura reports…

Posted on Updated on

… or Javadoc, or anything with frames.

It doesn’t appear to refresh correctly, and I was missing updates to my coverage.

Load them in a real browser instead.

Developing for TeamCity in Eclipse

Posted on

This document assumes you are running the TeamCity package from JetBrains, which includes Tomcat. If you are running your own Tomcat install, you may need to hunt out the files yourself. This document is based on Linux. I’ve tried to point out what you need to change on Windows, but I don’t have a Windows box to test with.

My TeamCity home  is /opt/TeamCity

Enable JSP development mode in Tomcat.

This setting alows you to hot delpoy JSPs, and Tomcat will re-compile them for you without a restart.  Edit <TeamCityHome>/conf/web.xml and find the JspServlet section. Change the development mode to true as per the section below.


Enable Java code hot-swapping with a debugger

We have enabled JSP hot-compile in the previous, now we need to configure Tomcat so that Eclipse can load new Java code into the JVM from within the Eclipse debugger.

For Linux, edit <TeamCityHome>/bin/ and insert the commands needed to start Tomcat with the debugger enabled. I added the TEAMCITY_DEBUG_OPTS variable, and then added it to the CATALINA_OPTS line.

TEAMCITY_DEBUG_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"

 CATALINA_OPTS="$CATALINA_OPTS $TEAMCITY_SERVER_OPTS $TEAMCITY_DEBUG_OPTS -server $TEAMCITY_SERVER_MEM_OPTS -Dlog4j.configuration=file:$BIN/../conf/teamcity-server-log4j.xml -Dteamcity_logs=../logs/ -Djava.awt.headless=true"

For Windows, edit <TeamCityHome>\conf\teamcity-server.bat and insert the debug commands. I added the TEAMCITY_DEBUG_OPTS variable, and then added it to the CATALINA_OPTS line.

SET TEAMCITY_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
SET CATALINA_OPTS=%TEAMCITY_SERVER_OPTS% %TEAMCITY_DEBUG_OPTS% -server %TEAMCITY_SERVER_MEM_OPTS_ACTUAL% -Dlog4j.configuration=file:../conf/teamcity-server-log4j.xml -Dteamcity_logs=../logs/

Start Tomcat

Stop Tomcat if it’s running and then start it by running <TeamCityHome>/bin/ start (or <TeamCityHome>\bin\teamcity-server.bat start on Windows).

Have a look in <TeamCityHome>/logs/catalina.out  There should be a line similar to the one below indicating that Tomcat is running with the debug port open.

Listening for transport dt_socket at address: 8000

Configure Eclipse

In Eclipse, create a new Debug Configuration (In the Java perspective, it’s under the Run menu).

Find Remote Java Application, and click the new button.  In the Connect tab, set:

  • Connection Type: Standard Socket (Attach)
  • Connection Properties:
    • Host: localhost (assuming your TeamCity instance is on your local machine)
    • Port: 8000

In the Source tab, I added my Java source directory.

Connect to Tomcat in Eclipse

Run the new Debug Config, and change to the Debug perspective. A quote from the TeamCity dev page is relevant here.

if you do not change code affecting plugin initialization and change only body of the methods, you can attach to the server process with a debugger and hot-swap the code

So if you change your registers or constructors, you need to restart Tomcat.

Deploy your JSPs

When TeamCity starts, it copies the JSPs from your plugin into <TeamCityHome>/webapps/ROOT/plugins/<YourPluginName>/

Therefore, you can copy updated JSPs to here. This might be best acheived with a simple ANT script.