Thanks to Brian E. Fox, I managed to avoid duplication of Flex remoting configuration files in this project. It requires a bit of additional configuration and I hope that Maven will soon provide a simpler way to do this simple resource inheritance thing. But in the meantime, this one will work.
I’m going to update my four–article series to include those modifications, but for those of you who have already gone through it before the update, here are the exact modifications you need to make to the project you got at the end of Part 4.
Creating the configuration module
The first thing we need to do is to create a new module under todolist. That module will contain our 2 configuration files and package them up in a resource zip that can be included later in both the web and ria modules.
So first go to todolist and run the following command:
mvn archetype:create -DgroupId=org.epseelon.samples -DartifactId=todolist-config
Then go to todolist-config and delete src/main/java and src/main/test directories. After that, create an src/main/resources directory and copy remoting-config.xml and services-config.xml from either todolist-web or todolist-ria to this resources directory.
Now you need to edit todolist-config/pom.xml like this:
<?xml version="1.0"?> <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"> <parent> <artifactId>todolist</artifactId> <groupId>org.epseelon.samples</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>org.epseelon.samples</groupId> <artifactId>todolist-config</artifactId> <name>todolist-config</name> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <id>make shared resources</id> <goals> <goal>single</goal> </goals> <phase>package</phase> <configuration> <descriptors> <descriptor>src/main/assembly/resources.xml</descriptor> </descriptors> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
Notice the pom packaging and configuration of maven assembly plugin to package configuration according to the assembly descriptor in src/main/assembly/resources.xml file as follows:
<assembly> <id>resources</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>src/main/resources</directory> <outputDirectory></outputDirectory> </fileSet> </fileSets> </assembly>
Now you can run ‘mvn install’ and you see a file called todolist-config-1.0-SNAPSHOT-resources.zip, with just our 2 configuration file inside.
Including this dependency in Flex module
First, you need to add the following dependency to todolist-ria/pom.xml:
<dependency> <groupId>${project.groupId}</groupId> <artifactId>todolist-config</artifactId> <version>1.0-SNAPSHOT</version> <classifier>resources</classifier> <type>zip</type> <scope>provided</scope> </dependency>
Then add the following plugin configuration after the one for flex-compiler-mojo:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>unpack-config</id> <goals> <goal>unpack-dependencies</goal> </goals> <phase>generate-resources</phase> <configuration> <outputDirectory>${basedir}/target/generated-resources</outputDirectory> <includeArtifacIds>todolist-config</includeArtifacIds> <includeGroupIds>${project.groupId}</includeGroupIds> <excludeTransitive>true</excludeTransitive> </configuration> </execution> </executions> </plugin>
This will unpack resources dependencies in target/generated-resources. Now we just need to include generated-resources on the resource path. To do that, add the following to the build element, right after defaultGoal:
<resources> <resource> <directory>${basedir}/src/main/resources</directory> </resource> <resource> <directory>${project.build.directory}/generated-resources</directory> <filtering>true</filtering> </resource> </resources>
The last thing we need to do now is to delete todolist-ria/src/main/resources with both configuration files in it because we don’t need it anymore.
You can run ‘mvn install’ again and compilation should pass, which would not be possible if flex-compiler-mojo hadn’t found both configuration files on its resource path.
Including configuration dependency in web module
The process is not very different. Just add the following dependency to todolist-web/pom.xml:
<dependency> <groupId>${project.groupId}</groupId> <artifactId>todolist-config</artifactId> <version>1.0-SNAPSHOT</version> <classifier>resources</classifier> <type>zip</type> <scope>provided</scope> </dependency>
Then since maven-dependency-plugin is already configured to copy swf dependencies over, we just have to add an execution configuration to configuration/executions in this plugin:
<execution> <id>unpack-config</id> <goals> <goal>unpack-dependencies</goal> </goals> <phase>generate-resources</phase> <configuration> <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/flex</outputDirectory> <includeArtifacIds>todolist-config</includeArtifacIds> <includeGroupIds>${project.groupId}</includeGroupIds> <includeClassifiers>resources</includeClassifiers> <excludeTransitive>true</excludeTransitive> <excludeTypes>jar,swf</excludeTypes> </configuration> </execution>
As you can see, the output directory is not the same here. We could have used generated-resources as above, but using target/todolist-web instead minimizes the amount of configuration since everything in this directory in included in the final package.
Now, you can delete src/main/webapp/WEB-INF/flex directory with both configuration files inside since we don’t need them anymore. And after running ‘mvn install’, you can check that both files are here as before.
Conclusion
The end result of this new project is exactly the same, but since finding out where to put those configuration files was one of my main concerns when trying to build a Flex Java-backed application with Maven, I think it’s far cleaner that way.
As always, here is the final project.
Enjoy!
21 responses to “Flex, Spring and BlazeDS: the full stack! (Epilogue)”
Hi Sébastien,
First of all, I would like to say thank you for posting this tutorial. I have followed your latest updates and unfortunately, I’ve got errors when running the app. The UI couldn’t establish connection to ‘todoService’. The latest code posted on this site, also has this problem.
It seems to me that compilation process of the todolist-ria omitted the resources in the todolist-config.
thanks,
Djail
Djail, could you send me your project at sebastien dot arbogast at gmail.com so that I can have a look?
Hi Sébastien and Djail,
Thank you Sébastien for this great tuturial. I was having great difficulty on trying to do exactly what you provide here but with ibatis instead of hibernate. Anyway, thanks again.
I had exactly same error that Djail encountered. here is the solution that works for me:
in todolist-ria/pom.xml, I change “${project.build.directory}” to “${basedir}/target” within element. that’s it.
I don’t know why it works because I don’t know much about Maven.
Thanks a lot JayChen: you are totally right, it seems that there is another important regression in Maven as project.build.directory is not resolved correctly. I did the same modification on the article and the project and now it should work for everybody. Thanks for the feedback!
Sebastien,
I am receiving errors myself preventing me from creating modules.
Using the files from Part 2, I go to part 3 and receive this error:
[ERROR] BUILD ERROR
[INFO] ————————————————————————
[INFO] Error creating from archetype
Embedded error: Unable to add module to the current project as it is not of packaging type ‘pom’
… which makes no sense to me.
Clues?
If you come from part 2, you should follow part 3 and 4. This epilogue is only applicable to people having gone through part 3 and 4 before they were fixed.
This kind of error happens when you try to create a new subproject using maven archetype plugin under a parent project whose packaging is not ‘pom’. Since the default packaging is ‘jar’, you need to add a <packaging>pom</packaging> element right under project in root pom.xml.
But really to be sure, you should just follow articles in order, and be sure not to forget anything, because nothing is superficial.
I was commenting here because this was the most recent entry.
“This kind of error happens when you try to create a new subproject using maven archetype plugin under a parent project whose packaging is not ‘pom’. Since the default packaging is ‘jar’, you need to add a pom element right under project in root pom.xml.”
OK. But:
1) I have the packaging set correctly in the root pom.xml file.
2) I am using your files from Part 2 to start off with in Part 3, so obviously you set the package to pom already
3) I am still getting the error.
If you like, I can copy and paste the same comment in the Part 3 entry if you need more context.
Leif
Hang on. I think I found my problem… sorry.
[…] Flex, Spring and BlazeDS: the full stack! (Epilogue) […]
Thanks a lot for this article series Sebastien!
It inspired me a lot and helped me getting started with a new project of mine.
Here is the first release : a blazeDS Xdoclet Spring Hibernate Maven Archetype:
see : http://www.jroller.com/francoisledroff/entry/a_blazeds_xdoclet_spring_hibernate
[…] qui permet de faire du remoting vers un serveur Java depuis une application Flex (rappelons l’excellente série d’articles sur Flex – BlazeDS par Sébastien […]
Hi, Thanks a lot for your work. I am using this with some modification (use h2database and jetty for easier testing).
One question I have is whenever I install or run it, maven will download blazeds modules again. Is this normal?
Might be because BlazeDS are deployed on my own repository without POM’s. Try to change the version of all 3 BlazeDS libraries to 3.0 instead of 3.0.0.544. It seems that someone has deployed those to a public Maven repositories with POM. Could you please let me know your results with that?
Thanks, sebastine. I changed the version of blazeDS to 3.0 and I does not try to download anything else any more.
I checked my local repos and found those jars with pom. Thanks for your excellent work again.
Btw, did you consider to make your example to run with embedded database (hsqldb or h2database) and embedded servlet container (jetty)? Then it will make your example work out-of-box.
Btw, I also realize that the blazeds-remoting in the central repos is depending on blazeds-core 1.0beta1 and blaze-common 1.0beta1. Should this be fixed?
This is really wrong. I’ll post a message on maven list about that.
Thanks Sabastien ,Great Article.
i an eager to see this running in embedded jetty.
Hi Sebastien,
have you run the pom lately to see if all the repositories are up to date?
I get
Missing:
———-
1) org.epseelon.samples:todolist-common:jar:1.0-SNAPSHOT
but I can’t find this module in any of the references repositories. Very frustrating!
Thanks,
Peder J.
You can’t get it from any other repository because it’s actually a module of this project. So it should be built before et deployed to your local repository. There must be an error in my POM or something but I don’t have time to look into that issue at the moment. From what I’ve heard, the project here on my blog builds fine, maybe you could compare them and spot the error.
Sorry about that, but I’m really busy right now.
OK, obviously there are 2 problems in my article on Adobe Developer Connection and I finally found the time to look into it:
First of all, there was a big error in one of the POMs in todolist3.zip. In todolist-web/pom.xml, if the first dependency looks like this:
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>todolist-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Then replace it with this:
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>todolist-config</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>resources</classifier>
<type>zip</type>
<scope>provided</scope>
</dependency>
And it should work fine.
The second error is in the article itself: of course, all of the namespace declarations should be xmlns:mx=”http://www.adobe.com/2006/mxml” instead of xmlns:mx=”/2006/mxml” .
I’ll try to reach ADC editor so that they can fix those mistakes. Thanks for the feedback.
[…] MySQL and a Maven build (2, 3rd part is still not published; Original series: 1, 2, 3, 4, 5) Tags: AJAX, BlazeDS, Cinnamon, Flex, GraniteDS, JSF, Spring, WebORB Related […]