Maven Plugins

About Maven

Maven is a build tool from the Java world, but can also be used to build Flex applications or in fact any application type you want. Maven is extendible through plugins, and we provide such plugins for Jangaroo. Using Maven is the recommended way to build your Jangaroo project.

Instead of a build.xml as known from Ant, Maven uses a file called pom.xml that contains the build information.

Jangaroo Maven Plugins

There are two Jangaroo Maven plugins: jangaroo-maven-plugin does the actual work, while jangaroo-lifecycle defines a Jangaroo-specific Maven packaging and dependency type. In a simple project, you will usually use war packaging (as provided by Maven), but you still have to declare the Jangaroo lifecycle plugin so that dependencies of type jangaroo are handled correctly.

jangaroo-maven-plugin defines several so-called Mojos (comparable to Ant's tasks) or goals. When used in a war packaging scenario, you have to execute at least the goals compile and war-package. The first compiles the ActionScript 3 sources of your module to JavaScript, the latter one extracts all dependent Jangaroo libraries (at least the Jangaroo runtime) to the Web application output directory. The compile Mojo provides configuration options that correspond to Jangaroo's compiler command line options.

The minimal pom.xml for the HelloWorld example looks like this:

<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">
  <modelVersion>4.0.0</modelVersion>
  <groupId>net.jangaroo.examples</groupId>
  <artifactId>hello-world</artifactId>
  <version>0.1.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>hello-world</name>
  <description>A Hello World Jangaroo Application</description>

  <properties>
    <jangaroo_version>0.6.0</jangaroo_version>
    <jangaroo_libs_version>0.6.0</jangaroo_libs_version>
  </properties>

  <pluginRepositories>
    <pluginRepository>
      <id>jangaroo</id>
      <name>Jangaroo repository</name>
      <url>http://repo.jangaroo.net/maven2</url>
    </pluginRepository>
  </pluginRepositories>

  <repositories>
    <repository>
      <id>jangaroo</id>
      <url>http://repo.jangaroo.net/maven2</url>
    </repository>
  </repositories>

  <build>
    <sourceDirectory>src/main/joo</sourceDirectory>
    <outputDirectory>target/joo</outputDirectory>

    <plugins>
      <plugin>
        <groupId>net.jangaroo</groupId>
        <artifactId>jangaroo-lifecycle</artifactId>
        <version>${jangaroo_version}</version>
        <extensions>true</extensions>
      </plugin>

      <plugin>
        <groupId>net.jangaroo</groupId>
        <artifactId>jangaroo-maven-plugin</artifactId>
        <version>${jangaroo_version}</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>war-package</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>

    <dependency>
      <groupId>net.jangaroo</groupId>
      <artifactId>jangaroo-browser</artifactId>
      <version>${jangaroo_libs_version}</version>
      <type>jangaroo</type>
    </dependency>

  </dependencies>

</project>

Let me walk you through this file:

Besides the usual Maven settings, you have to tell Maven where to find the Jangaroo plugins (pluginRepository) and artefacts (repository).

Since we are building a war artifact, you have to configure the special Jangaroo source and output directory.

Next is the declaration of both Jangaroo Maven plugins: the lifecycle and the compiler.  Maven plugins, like every Maven artefact, are referenced by a groudId together with an artifactId and a version. Mind to set extensions to true for the lifecycle to be effective! The compiler plugin is supposed to execute the goals compile and war-package.

The third plugin configuration of maven-war-plugin is unfortunately necessary to avoid complaints about a missing web.xml file.

Then we have exactly one dependency, namely jangaroo-browser, which provides an ActionScript 3 view of the browser DOM and BOM APIs. This library is needed by almost every Jangaroo project and also provides an implicit dependency on jangaroo-runtime, which is always needed. So if you don not use jangaroo-browser, be sure to replace it by a dependency to jangaroo-runtime.

To build the project, run mvn package in the directory containing pom.xml. Obviously, a working Maven2 installation is required to do so. This compiles the *.as files into *.js files and assebles these and all Web resources in the folder target/hello-world-0.1.0-SNAPSHOT. Open index.html in any browser and be exited about the beautiful line of text that appears as by magic!

The Web application is also packaged into a *.war file in the target folder, which is just a zip archive of the folders and files to deploy to your Web space.