Not sure this should be here, but thought I should document how I got started on a RSF project. (I wouldn't even assume that this project will ever get anywhere, but documenting a getting started with RSF could be helpful...)
World is my "dream" project of getting a decent Email Calendar Task-List thing started. Some would call it a PIM, some others would call it insane and would query why I'm even bothering however, I shall begin and no doubt promptly forget about this when term and thus work starts in earnest... :p
OK for starters... Lets take a look at what the basic pom.xml should be.
First off I assume I'll be needing RSFHibernate3 and some other things so I guess I'll need a pom thus:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <name>RSF World</name> <groupId>org.zeripath</groupId> <artifactId>world</artifactId> <organization> <name>CARET</name> <url>http://www.caret.cam.ac.uk</url> </organization> <inceptionYear>2007</inceptionYear> <version>1.0</version> <packaging>war</packaging> <parent> <groupId>uk.org.ponder.pure-poms</groupId> <artifactId>standard-war</artifactId> <version>POM-3</version> </parent> <properties> <rsfutil.version>0.7.2</rsfutil.version> </properties> <repositories> <repository> <id>CARET-Maven2</id> <name>CARET Maven 2 Repository</name> <url>http://www2.caret.cam.ac.uk/maven2</url> </repository> <repository> <id>CARET-Maven2-dev</id> <name>CARET Maven 2 Dev Repository</name> <url>http://www2.caret.cam.ac.uk/maven2dev</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> <dependencies> <dependency> <groupId>uk.org.ponder.rsfutil</groupId> <artifactId>rsfutil</artifactId> <version>${rsfutil.version}</version> <type>jar</type> </dependency> <dependency> <groupId>uk.org.ponder.rsfutil</groupId> <artifactId>RSFComponents-evolvers</artifactId> <version>${rsfutil.version}</version> <type>jar</type> </dependency> <dependency> <groupId>uk.org.ponder.rsfutil</groupId> <artifactId>rsfhibernate3</artifactId> <version>${rsfutil.version}</version> <type>jar</type> </dependency> <dependency> <groupId>uk.org.ponder.rsfutil</groupId> <artifactId>RSFComponents-templates</artifactId> <version>${rsfutil.version}</version> <type>war</type> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.0.4</version> <type>jar</type> </dependency> </dependencies> <build> <resources> <resource> <directory>src/main/resources</directory> </resource> </resources> </build> </project>
Not entirely sure that's minimal nor quite what the parent pom is about. I expect I don't need that.
Now we want a datamodel, and we don't want to be messing around too much with it, so lets try to get a maven-hibernate3 plugin working.
I'll first make the project multiproject by moving the webapp part out and adding a dependence on world-datamodel. then I'll create a datamodel project.
datamodel/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <name>RSF World Datamodel</name> <groupId>org.zeripath</groupId> <artifactId>world-datamodel</artifactId> <organization> <name>CARET</name> <url>http://www.caret.cam.ac.uk</url> </organization> <inceptionYear>2007</inceptionYear> <version>1.0</version> <packaging>jar</packaging> <repositories> <repository> <id>CARET-Maven2</id> <name>CARET Maven 2 Repository</name> <url>http://www2.caret.cam.ac.uk/maven2</url> </repository> <repository> <id>CARET-Maven2-dev</id> <name>CARET Maven 2 Dev Repository</name> <url>http://www2.caret.cam.ac.uk/maven2dev</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> <repository> <id>Codehaus Snapshots</id> <url>http://snapshots.repository.codehaus.org/</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>false</enabled> </releases> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>Codehaus Snapshots</id> <url>http://snapshots.repository.codehaus.org/</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>false</enabled> </releases> </pluginRepository> </pluginRepositories> <dependencies> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.0.4</version> <type>jar</type> </dependency> </dependencies> <build> <resources> <resource> <directory>src/main/resources</directory> <excludes><exclude>hibernate.cfg.xml</exclude></excludes> </resource> </resources> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>hibernate3-maven-plugin</artifactId> <version>2.0-SNAPSHOT</version> <executions> <execution> <goals> <goal>hbm2java</goal> </goals> </execution> </executions> <configuration> <hibernate> <configurationFile>/src/main/resources/hibernate.cfg.xml</configurationFile> </hibernate> </configuration> </plugin> </plugins> <extensions> <extension> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.5</version> </extension> </extensions> </build> </project>Again I'm not sure whether this is minimal...
Now in src/main/resources/ create a hibernate.cfg.xml and mappings.hbm.xml:
hibernate.cfg.xml
<?xml version="1.0"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <mapping resource="mappings.hbm.xml"/> </session-factory> </hibernate-configuration>
mappings.hbm.xml should be of the type of hibernate-mapping
Now the rather confusing thing is: hbm2java relies the mappings files being in target/classes for it to see them This means that the hibernate3:hbm2java goal will run in the process-resources phase rather than generate-sources. (This confused me for some time.)
Now if you've got it all correct mvn install should compile and create a working datamodel for you. Wooness...