Archive for the ‘exploring-hibernate-series’ Category

Adding basic build automation for a web application project using ANT

December 9, 2008

We add the ability to build the projects source and generate an executable artifact that can be deployed to an application server capable of running WAR files. In this example we are using tomcat and thus also add support for managing the application through ANT to aid development.

We also add eclipse launch configurations so the developer can easily execute specific ant targets rather than typing they via the command link or executing them from eclipses ANT view.

Creating ANT build.xml

The build.xml goes at the root of the project and within it we add the following public.

  1. Clean – responsible for cleaning generated files that are not part of the source of the application i.e. .class files. Basically clean should be able to revert the workspace to the same state repeatedly and that should mirror the state of the project when checked out of source control.
  2. Compile – responsible for compiling all source files required for the application. Thus it will require knowledge of the dependencies required for the source to compile.
  3. Test – this target will invoke all tests that are added. The method behind the development of this software is that developers add tests as new functionality is added and all tests should be passing before checking the code back into source control.
  4. Build – this target is responsible for generating the software deliverable we need;  A WAR file. It cleans, compiles, tests and then packages up the compiled code into a WAR file for deployment to a web container.

Adding tomcat support for Development

We can use the catalina-ant.jar file from the tomcat distribution and create macros around them to allow developers to quickly deploy, undeploy applications on a specific tomcat instance.

To do this we create tomcat.properties, tomcatTasks.properties and tomcat-macros.xml files. Then we adding the following public targets to our build.xml file

  1. deploy
  2. undeploy

Using Eclipse External Tool Configurations

To make things even easier, we can integrate our IDE (Eclipse) and our build tool (ANT) and create configurations that we can maintain in source control. As these are IDE specific, they can be contained within a folder within the project but the build itself knows nothing of this folder.

Choose option from eclipse configuration menu:
eclipse-configuration-menu

The project structure after build automation has been added
build-automation-with-eclipse-launch-configurations

Note: the eclipse specific launch configuration files

Advertisements

Dependencies of Spring/Hibernate/HSQLDB web application

December 7, 2008

Add the following dependencies to your project as described below and show in the picture:

Test dependencies

Put the following dependencies into the lib/test folder:

  1. junit-4.4.jar
  2. jmock-2.5.1.jar + dependencies
  3. hamcrest-core-1.1.jar + hamcrest-library-1.1.jar from Jmock download

Tools/Compilation dependencies

Put the following dependencies into the lib/compile folder:

  1. hibernate-tools.jar + dependencies (latest version compatible with hibernate 3.3.x
  2. catalina-ant.jar from tomcat 6.0.18 download
  3. servlet-api-2.5.jar from tomcat 6.0.18 download

Runtime dependencies

Put the following dependencies into the lib folder:

  1. spring 2.5.6 + dependencies
  2. spring-webmvc.jar
  3. jstl.jar and standard.jar (from spring framework download dist folder)
  4. joda-time-1.6.jar
  5. hsqldb-1.8.0.7.jar
  6. hibernate3.3.1.jar + dependencies (including slf4j-simple-1.5.2.jar)
  7. commons-logging.jar, commons-lang.jar, commons-collections-3.1.jar (from spring framework download dist folder)

Dependencies of Spring/Hibernate Web Application

hibernate-spring-web-dependencies

Create project structure on Eclipse for spring/hibernate web application

December 7, 2008
  1. On eclipse create a new repository location that points to the SVN source of the project.
  2. If repository is empty create a new remote folder under trunk.
  3. Checkout the project and create the project structure displayed below and check back into source control.

hibernate-war-structure1

Set the target-eclipse project as the output folder for the project on eclipse.

Exploring Hibernate Series: Introduction

December 7, 2008

This the first post in a series of posts that will look at using hibernate ORM (object-relational mapping). The code for each part in the series can be browsed our checkout through svn. Details on this will exist at http://code.google.com/p/exploring-hibernate-series/

The domain for this web application will be as a defect tracking tool. The application will be developed in an iterative and incremental fashion and test-driven development (TDD) technique will be used to develop it.

The following technologies will be used throughout the series.

ANT 1.7.1
Java 1.5
Spring Framework 2.5
SpingMVC 2.5
Hibernate 3.3.1
HSQLDB 1.8

JUnit 4.4
JMock 2.5.1
WebDriver (latest binaries)