Maven script to build Flex portlet

As you might have seen in the last few days i am working on using Flex inside the portlet and i did built quite a few portlets to demonstrate how that works.

The building and deployment was very painful, first i had to make changes in the .mxml export it as .swf from Flex builder into the WebContent folder of my portlet then export portlet with new .swf and install it on portal.

In order to simplify this process i built a mvn script which can be used to build .mxml in .swf, copy it into the WebContent folder, package the portlet and then deploy it in the pluto, this is the script that i am using.



<?xml version="1.0" encoding="UTF-8"?>
<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">

<!-- Change this to something akin to your java package structure -->
<groupId>com.webspherenotes.portlet</groupId>
<modelVersion>4.0.0</modelVersion>
<!-- Version of this app -->
<version>0.1-alpha1</version>
<!-- Base name of the war file without .war ext -->
<artifactId>HelloWorldPortlet</artifactId>
<packaging>war</packaging>
<name>${pom.artifactId}</name>
<!-- Dependency Version Properties ======================================= -->
<properties>
<pluto.version>2.0.0</pluto.version>
<portlet-api.version>2.0</portlet-api.version>
<servlet-api.version>2.4</servlet-api.version>
<jsp-api.version>2.0</jsp-api.version>
<junit.version>3.8.1</junit.version>
<pluto.home>C:/software/pluto-2.0.0</pluto.home>
<flex.home>C:/software/AdobeFlashBuilder/sdks/4.0.0</flex.home>
<flex.mxml.path>C:/flex/HelloFlex/src/HelloWorld.mxml</flex.mxml.path>
<flex.swf.name>HelloWorld.swf</flex.swf.name>
</properties>
<dependencies>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>${portlet-api.version}</version>
<scope>provided</scope><!-- Prevents addition to war file -->
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.portals.pluto</groupId>
<artifactId>pluto-util</artifactId>
<version>${pluto.version}</version>
<scope>provided</scope>
</dependency>
<!-- Any other build or deployment dependancies go here -->
</dependencies>
<build>
<finalName>${pom.name}</finalName>
<plugins>

<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<configuration>
<tasks>
<property environment="env"/>
<!-- This assumes that you have set a CATALINA_HOME environmental variable
<property name="pluto.home" value="C:/software/pluto-2.0.0"/>-->
<copy file="target/${pom.name}.war" todir="${pluto.home}/webapps"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- configure to use Java 6 to compile (change to your JDK) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<!-- configure maven-war-plugin to use updated web.xml -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>${project.build.directory}/pluto-resources/web.xml</webXml>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.portals.pluto</groupId>
<artifactId>maven-pluto-plugin</artifactId>
<version>${pluto.version}</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<property name="FLEX_HOME" value="${flex.home}"/>
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar"/>
<mxmlc file="${flex.mxml.path}" keep-generated-actionscript="false"
output="${project.build.directory}/${project.name}/${flex.swf.name}">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
<include name="libs" />
<include name="../bundles/{locale}" />
</compiler.library-path>
</mxmlc>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

2 comments:

Anonymous said...

Thank you, Sunil. I am trying to mavenize a build for a legacy flex application and this was a very helpful example.

Abhi said...

Thanks for info....
SEO Company in Bangalore