samedi 27 novembre 2010

GraniteDS Maven archetypes 1.0 RC1 released

We have noticed from a long time that starting a new project with GraniteDS and the usual Java frameworks is not easy enough. We have tried to simplify the configuration as much as possible by allowing to configure GraniteDS directly in the Spring and Seam configuration files but yet there are many steps and caveeats that can take lots of time when setting up a project. It is even more painful when you add the setup of the build system with Ant or Maven.

Fortunately Maven provides a handy mechanism to bootstrap new projects in the form of archetypes. Along with the release of GraniteDS 2.2, we have also released a set of 4 archetypes for common use cases of GraniteDS :
  • graniteds-spring-jpa-hibernate: Flex 4 + Spring 3 + Hibernate/JPA + GraniteDS with standard RemoteObject API
  • graniteds-tide-spring-jpa-hibernate: Flex 4 + Spring 3 + Hibernate/JPA + GraniteDS with Tide API
  • graniteds-tide-seam-jpa-hibernate: Flex 4 + Seam 2.2 + Hibernate/JPA + GraniteDS with Tide API
  • graniteds-tide-cdi-jpa: Flex 4 + CDI/Weld 1.0 + JPA + GraniteDS with Tide API
It is recommended to use Maven 3 but Maven 2.2 should also work. You can run the archetypes from the command line :
mvn archetype:generate
-DarchetypeGroupId=org.graniteds.archetypes
-DarchetypeArtifactId=graniteds-tide-spring-jpa-hibernate
-DarchetypeVersion=1.0.0.RC1
-DgroupId=com.myapp
-DartifactId=example1 -Dversion=1.0-SNAPSHOT
This will create of project named example1 that you can directly build and run with maven :
cd example1
mvn install
cd webapp
mvn jetty:run-war
Then browse http://localhost:8080/example1/example1.swf. The generated project is a multimodule application skeleton with a Java module, a Flex module and a Web module. It includes basic security, service remoting and data synchronization. The default security configuration includes two hardcoded users: admin/admin and user/user.

It is a good starting point to build your own application, after removing the very few example parts. The most interesting thing in these archetypes is that the build poms are automatically created and that they reference selected versions of each framework (Flex, Spring, Seam, Hibernate...) and of build tools (Flexmojos, Jetty plugin...) that work together correctly.

Spring and Seam archetypes are built to be run inside Jetty (for example with the Maven Jetty plugin as shown before). The CDI/Weld example is built to be run inside GlassFish v3.0.1+ and should also work in JBoss 6 M4 (but not later as next versions include the newer and incompatible Weld 1.1). By default it can be run in embedded GlassFish with :
cd example1
mvn install
cd webapp
mvn embedded-glassfish:run
If you don't want to run inside an embedded container but in Tomcat or another container, and still want to use real-time messaging, you will have to change the Gravity servlet implementation in the web.xml file (implementation class names for Tomcat and JBoss 5+ are in comment in the generated web.xml). Then build a war to be deployed in any application server with :
cd webapp
mvn war:war
This is not a final release of these archetypes but they are already usable. They mostly miss the necessary Maven stuff to run unit tests for Flex and Java projects.

As always don't hesitate to give your feedback.

jeudi 25 novembre 2010

Upgrading from GraniteDS 2.1 to GraniteDS 2.2

GraniteDS 2.2 GA has just been released. There have been a few minor changes in APIs and configurations that require some work when upgrading from GDS 2.1 to GDS 2.2 :

API for PagedQuery

PagedQuery now supports sorting on multiple fields, so the API for server-side components has been changed accordingly and expects arrays for order and desc.
public Map find(Map filter, int first, int max, String[] order, boolean[] desc) {
...
}

Configuration property of server-side validator

The property name in services-config.xml has changed from validator-class-name to validatorClassName for consistency with other properties :
<destination id="seam">
<properties>
<validator-class-name>org.granite.tide.hibernate.HibernateValidator</validator-class-name>
</properties>
</destination>
With Spring, it's also possible to define a validator-name that is the name of a bean that implements org.granite.tide.validators.EntityValidator, the default name expected being "tideValidator".
<bean id="tideValidator" class="com.myapp.MyValidator"/>