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!













April 23rd, 2008 at 10:03 am
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
April 23rd, 2008 at 9:02 pm
Djail, could you send me your project at sebastien dot arbogast at gmail.com so that I can have a look?
April 26th, 2008 at 4:38 am
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.
April 30th, 2008 at 10:35 pm
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!
April 30th, 2008 at 11:33 pm
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?
April 30th, 2008 at 11:49 pm
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.
April 30th, 2008 at 11:59 pm
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
May 1st, 2008 at 12:21 am
Hang on. I think I found my problem… sorry.
May 5th, 2008 at 6:54 pm
[...] Flex, Spring and BlazeDS: the full stack! (Epilogue) [...]
May 24th, 2008 at 7:33 pm
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
May 26th, 2008 at 6:19 pm
[...] 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 [...]
June 4th, 2008 at 5:56 pm
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?
June 4th, 2008 at 6:01 pm
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?
June 5th, 2008 at 6:29 am
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.
June 5th, 2008 at 6:34 am
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?
June 5th, 2008 at 8:01 am
This is really wrong. I’ll post a message on maven list about that.
June 7th, 2008 at 12:41 pm
Thanks Sabastien ,Great Article.
i an eager to see this running in embedded jetty.