Monday, February 9, 2009

Maven2 - BlazeDS, ActiveMQ and Flex project structure

(this is mostly the same as the great article from Sebastien Arbogast, I'm adapting it slightly to our needs and will focus more on the Eclipse/debug integration later on, but you should really read his post)

First up, getting the Maven project laid out!
mvn archetype:create -DgroupId=com.mycompany -DartifactId=myproject
I don't know of any way to generate the parent pom directly, so it's a couple quick steps to clean this up.
2) Go into the "myproject" directory and delete the src folder
3) Edit the pom.xml file and change the packaging element to "pom" instead of "jar" (while you're at it, go ahead and change the JUnit version to 4.5, might as well stay current)

Now that we've got the parent pom set up, let's start adding subprojects. We're going to need a Flex module, you have your choice of a couple projects, but the most promising one seems to be flex-mojos
First a quick stop back at our parent pom.xml file, add in the following before the dependencies element:
<repositories>
<repository>
<id>flex-mojos-repository</id>
<url>http://flex-mojos.googlecode.com/svn/trunk/repository/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>flex-mojos-repository</id>
<url>http://flex-mojos.googlecode.com/svn/trunk/repository/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
Then after the dependencies section add in:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-3</version>
</plugin>
</plugins>
</pluginManagement>
</build>


NOW create the Flex project... (this is all on ONE line)
mvn archetype:create -DarchetypeArtifactId=maven-archetype-flex -DarchetypeVersion=1.0 -DarchetypeGroupId=dk.jacobve.maven.archetypes -DgroupId=mycompany -DartifactId=myproject-ria -DpackageName=com.donbest
If you open up the pom.xml in the parent folder, we should see a new "modules" section
<modules>
<module>mycompany-ria</module>
</modules>

You should also now see another folder in this directory called "myproject-ria". We've got to make a couple quick changes here too... first remove the "properties" element since we're not going to use the "israfil" plugin. Next remove the plugin section itself and replace it with
<plugin>
<groupId>info.rvin.mojo</groupId>
<artifactId>flex-compiler-mojo</artifactId>
<version>1.0-beta7</version>
<extensions>true</extensions>
<configuration>
<locales>
<param>en_US</param>
</locales>
</configuration>
</plugin>

As the last step in the myproject-ria pom.xml, add the Flex dependencies...
<dependencies>
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>playerglobal</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>swc</type>
<scope>external</scope>
</dependency>
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>flex</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>framework</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>framework</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>resource-bundle</type>
<classifier>en_US</classifier>
</dependency>
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>rpc</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>rpc</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>resource-bundle</type>
<classifier>en_US</classifier>
</dependency>
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>utilities</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>swc</type>
</dependency>
</dependencies>

Whew, that was rough! But now you should be able to go to the parent folder and run
mvn install

No comments: