Start a New Spring-Hibernate-Tapestry Project

Tapestry 4 archetype – http://www.joshlong.com/jl/entry/20070227

Before You Begin

If you’ve never used Maven before, you’ll need to install Maven and add a M2_REPO classpath variable to your Eclipse preferences, under Window/Preferences/Java/Build Path/Classpath Variables. Maven will create a repository for you in your home directory in the .m2/repository directory, so your M2_REPO value should be something like C:\Documents and Settings\username\.m2\repository or /home/username/.m2/repository.
Please note that the sample project requires Java 5.

Run the Archetype

To start a project, use

mvn archetype:create -DarchetypeGroupId=com.codecafe.archetypes \
  -DarchetypeArtifactId=tapestry-simple                         \
  -DremoteRepositories=http://codecafe.dev-hda.com/repository   \
  -DarchetypeVersion=4.1.2-SNAPSHOT -DgroupId=ca.intelliware    \
  -DartifactId=myProject

This will create a new project in a new directory for the named artifact (myProject) in this case.

Then change directories

cd myProject

into the project and run

mvn -DdownloadSources=true eclipse:eclipse

If it falls over wanting jta-1.0.1B.jar, do the following:

  1. copy the jta-1.0.1B.jar from iwdbackup to your local file system
  2. run a special Maven command to install it into your local Maven repository:

mvn install:install-file -Dfile=jta-1.0.1B.jar -DgroupId=javax.transaction \
  -DartifactId=jta -Dpackaging=jar -Dversion=1.0.1B

That gets you a skeleton project with Spring and Tapestry that you can import into Eclipse and start working with. You can run your site with

mvn jetty6:run

and see the results at http://localhost:8080/myProject/app, or use MyEclipse or some other mechanism to deploy and run it.

We intend to have our own Spring/Hibernate/Tapestry/Intelliware Commons/{Acegi?} archetype at some point Real Soon Now, which will include some simple unit tests for the code included in the archetype.

Add Hibernate

To add Hibernate, add the following to the pom.xml:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate</artifactId>
    <version>3.2.1.ga</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-annotations</artifactId>
    <version>3.2.1.ga</version>
</dependency>

If you want HSQL, also add

<dependency>
    <groupId>hsqldb</groupId>
    <artifactId>hsqldb</artifactId>
    <version>1.8.0.7</version>
</dependency>

or if you want MySQL, use

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.0.5</version>
</dependency>

or so forth.

It also might be worthwhile to keep your web layer and your data layer in separate projects. See Split Your Project Into Sub-Projects for more information about how to set your project up in a multiproject structure.

Add More

Want to add more dependencies? Look up your package through the search engine at http://mvnrepository.com and copy the dependency stanza from the result page into the dependencies part of your pom.xml. It’s that simple.

For internal projects within Intelliware, Intelliware Commons modules may be similarly consumed as dependencies:

<dependency>
    <groupId>ca.intelliware.commons</groupId>
    <artifactId>migrator</artifactId>
    <version>1.1</version>
</dependency>

You can even specify ranges for versions using the mathematical syntax for number ranges. For example, if you need Hibernate 3.2 or later, but don’t care whether it’s 3.2, 3.2.1, or 3.2.2, you could specify

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate</artifactId>
    <version>[3.2,)</version>
</dependency>

Be sure to re-run mvn eclipse:eclipse whenever you add or remove a dependency to your pom.xml.

Hook Up to Repository and Source Control

For internal Intelliware projects, you’ll want to include our parent POM, which has pointers to our internal Maven repository. Add a stanza to your pom.xmllike this:

<parent>
	<groupId>ca.intelliware</groupId>
	<artifactId>pom</artifactId>
	<version>1.0.0</version>
</parent>

If you’re reading this from outside Intelliware, see the Maven docs for instructions on how to set up repositories in your pom.xml and settings.xml.

You’ll also need to add source control to your project. Add a stanza like this to your pom.xml:

<scm>
	<connection>scm:svn:http://subversion.intelliware.ca/rep/myCustomer/myProject/${artifactId}/trunk</connection>
	<developerConnection>scm:svn:http://subversion.intelliware.ca/rep/myCustomer/myProject/${artifactId}/trunk</developerConnection>
	<url>http://subversion.intelliware.ca/rep/myCustomer/myProject/${artifactId}</url>
</scm>

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

1 thought on “Start a New Spring-Hibernate-Tapestry Project

  1. Pingback: Array | i-proving.com

Leave a Reply