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.

15 commentaires:

maximilien a dit…

hi,

once project is generated, is it possible to get flash builder features with this maven project ?

For example if i import the project into flash builder and open mxml files, CDATA scripts are not colorized neither autocompleted.

Maximilien

William Draï a dit…

You can use mvn flexmojos:flexbuilder in the flex project to generate the necessary flexbuilder files (this is the equivalent of mvn eclipse:eclipse for Flex projects).
Note: there is a bug in flex mojos 3.7.1 with maven 3, you have to change flex mojos version to 3.8 in the main pom to be able to use this :
3.8

Unknown a dit…

This is *very* good timing ! I'm just starting a GraniteDS + Tide + Spring + Hibernate/JPA project, and this is going to save me a ton of time ... Thanks a lot for this archetype !

Unknown a dit…

Hi,
The base graniteds-spring-jpa-hibernate archetype doesn't compile "ootb". Here are the commands I executed:
> mvn archetype:generate -DarchetypeGroupId=org.graniteds.archetypes -DarchetypeArtifactId=graniteds-spring-jpa-hibernate -DarchetypeVersion=1.0.0.RC1 -DgroupId=com.mytest -DartifactId=example -Dversion=1.0-SNAPSHOT

> cd example
> mvn install

The error is the following:
source\example\flex\src\main\flex\Main.mxml:[56,-1] Type was not found or was not a compile-time constant: Welcome.
[ERROR] E:\users\ium\privateSource\source\example\flex\src\main\flex\Main.mxml:[41,-1] Call to a possibly undefined method Welcome.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] example ........................................... SUCCESS [0.221s]
[INFO] GraniteDS Spring JPA/Hibernate Java ............... SUCCESS [0.548s]
[INFO] GraniteDS Spring JPA/Hibernate Flex ............... FAILURE [4.129s]
[INFO] GraniteDS Spring JPA/Hibernate Web App ............ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.895s
[INFO] Finished at: Mon Dec 27 18:04:43 CET 2010
[INFO] Final Memory: 13M/150M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonatype.flexmojos:flexmojos-maven-plugin:3.7
.1:compile-swf (default-compile-swf) on project example-flex: Error compiling! -> [Help 1]

I tried the graniteds-tide-spring-jpa-hibernate, and it worked fine. However I'd prefer to not have Tide for the moment as I'd like to start with basic Graniteds.

William Draï a dit…

@David: Thanks for the report, this is simply a typo in flex/pom.xml.
Just change you own package in the section : com.myapp.entities.**

It will be fixed in RC2.

phil a dit…

Can you add Flex Controllers, SEAM Conversations and Joda time?

marekd a dit…

The java part of the granite-tide-cdi-jpa does not compile as the maven-compiler-plugin sets the java version to 1.5 and ObserveAllPublishAll has the @Override annotation over the implemented method. Or maybe I am missing something?

William Draï a dit…

@phil this will be in a next release, the first step is to be able to easily start a new project

@marekd it seems you're right but I don't have any problem compiling the Java part of CDI with maven 3.0 and jdk 6. Which version of maven are you using ?

marekd a dit…

Well, it's more about my eclipse (with the m2eclipse plugin) that detects the 1.5 compiler version and expects the code to be 1.5 compatible but apparently it is not.

John a dit…

Just now got around to trying these out. Thank you very much. This helps out.

John

Whitney a dit…

Hello and Thanks for this post. Could some one give some direction: I am using the graniteds-tide-spring-jpa-hibernate archetype and was able to get the sample up and running and logged in with no problem. I then tried to get the Gravity servlet working. I'm using apache-tomcat-6.0.20, I modified my web.xml file as instructed. dropped in tcnative-1.dll. Modified my server.xml as seen below. Here's the error I'm getting followed by the server.xml file.

Thanks, Whitney


Jan 18, 2011 10:29:33 PM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.12.
Jan 18, 2011 10:29:33 PM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
Jan 18, 2011 10:29:34 PM org.apache.coyote.http11.Http11AprProtocol init
SEVERE: Error initializing endpoint
java.lang.Exception: Socket bind failed: [730014] The system detected an invalid pointer address in attempting to use a pointer argument in a call.
at org.apache.tomcat.util.net.AprEndpoint.init(AprEndpoint.java:623)
at org.apache.coyote.http11.Http11AprProtocol.init(Http11AprProtocol.java:107)
at org.apache.catalina.connector.Connector.initialize(Connector.java:1058)
at org.apache.catalina.core.StandardService.initialize(StandardService.java:677)
at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:795)
at org.apache.catalina.startup.Catalina.load(Catalina.java:535)
at org.apache.catalina.startup.Catalina.load(Catalina.java:555)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:260)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:412)
Jan 18, 2011 10:29:34 PM org.apache.catalina.startup.Catalina load
SEVERE: Catalina.start
LifecycleException: Protocol handler initialization failed: java.lang.Exception: Socket bind failed: [730014] The system detected an invalid pointer address in attempting to use a pointer argument in a call.
at org.apache.catalina.connector.Connector.initialize(Connector.java:1060)
at org.apache.catalina.core.StandardService.initialize(StandardService.java:677)
at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:795)
at org.apache.catalina.startup.Catalina.load(Catalina.java:535)
at org.apache.catalina.startup.Catalina.load(Catalina.java:555)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:260)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:412)
Jan 18, 2011 10:29:34 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1691 ms







































































Whitney a dit…

Sorry here's the server.xml file:



































































William Draï a dit…

@Whitney: maybe try a more recent version of tcnative.dll.

Lassa@d a dit…

Hi, i'm using graniteds-spring-jpa-hibernate and i did compile and run it from the windows console, but when i did import the project into eclipse from the m2e, i found the 3 modules of the project and the root project, but i can't run the flex application from eclipse (run as flex application or run as web application), however the web app project was in the apache tomcat server and the server is runing well. Please tell how to run the flex application from eclipse and thank you very much :)

Gexton a dit…

granite countertops edmonton
Thanks, you guys that is a great explanation. keep up the good work.