Maven, Flex, and LiveCycle DS

I finally got back to continuing my experiments with Java and Flex. I wish Adobe would bundle some build files (like ant build.xml, maven pom.xml) with their LiveCycle DS (LCDS) examples.

So here’s what I’ve done so far. After following the steps in Flex, Spring and BlazeDS: the full stack blog, I made some modifications to make it use LCDS (instead of BlazeDS).

    <properties>
        <flex.dataservices.groupId>com.adobe.flex</flex.dataservices.groupId>
        <flex.dataservices.artifactId>flex-messaging</flex.dataservices.artifactId>
        <flex.dataservices.version>2.6-beta2</flex.dataservices.version>
    </properties>

    <dependencies>
        <!-- LiveCycle Data Services compile dependencies -->
        <dependency>
            <groupId>${flex.dataservices.groupId}</groupId>
            <artifactId>${flex.dataservices.artifactId}-data</artifactId>
            <version>${flex.dataservices.version}</version>
        </dependency>
        <dependency>
            <groupId>${flex.dataservices.groupId}</groupId>
            <artifactId>${flex.dataservices.artifactId}-core</artifactId>
            <version>${flex.dataservices.version}</version>
        </dependency>
        <dependency>
            <groupId>${flex.dataservices.groupId}</groupId>
            <artifactId>${flex.dataservices.artifactId}-common</artifactId>
            <version>${flex.dataservices.version}</version>
        </dependency>

        <!-- LiveCycle Data Services runtime dependencies -->
        <dependency>
            <groupId>${flex.dataservices.groupId}</groupId>
            <artifactId>${flex.dataservices.artifactId}-data-req</artifactId>
            <version>${flex.dataservices.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>${flex.dataservices.groupId}</groupId>
            <artifactId>${flex.dataservices.artifactId}-opt</artifactId>
            <version>${flex.dataservices.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>${flex.dataservices.groupId}</groupId>
            <artifactId>${flex.dataservices.artifactId}-proxy</artifactId>
            <version>${flex.dataservices.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>${flex.dataservices.groupId}</groupId>
            <artifactId>${flex.dataservices.artifactId}-remoting</artifactId>
            <version>${flex.dataservices.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>backport-util-concurrent</groupId>
            <artifactId>backport-util-concurrent</artifactId>
            <version>3.1</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>concurrent</groupId>
            <artifactId>concurrent</artifactId>
            <version>1.3.4</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.0.1</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>

        <!--
        <dependency>
            <groupId>com.adobe.blazeds</groupId>
            <artifactId>blazeds-core</artifactId>
            <version>${blazeds.version}</version>
        </dependency>
        <dependency>
            <groupId>com.adobe.blazeds</groupId>
            <artifactId>blazeds-remoting</artifactId>
            <version>${blazeds.version}</version>
        </dependency>
        <dependency>
            <groupId>backport-util-concurrent</groupId>
            <artifactId>backport-util-concurrent</artifactId>
            <version>3.1</version>
            <scope>runtime</scope>
        </dependency>
        -->
    </dependencies>

Since the LCDS JARs are not available in the remote Maven repository, I had to load them into my local repository manually (via mvn install:install-file). The LCDS JARs are found under the resources/libs folder of the LCDS installation.

Note that I’m using LCDS version 2.6 beta 2. It’s a bit different from version 2.5.x (called Flex Data Services).

After a successful build, I moved on to adding Hibernate and Spring. I looked at the samples that come with LCDS. I was sad to see that there was no sample that uses the Spring Framework. I remember seeing it when it was still called Flex Data Services.

I decided to use the CRM sample as a starting point. I copied the corresponding Java source files into my web module, and the Flex source files into my ria module. I also copied the necessary elements (i.e. <destination id="crm-company"> and <destination id="crm-employee">) into my config module’s data-management-config.xml file.

I tried to run the CRM sample using Maven via jetty plugin (mvn clean package jetty:run). The Flex client keeps on saying “unable to access UserTransaction”. So, I did some research and came up with a change in my web module’s POM to have Jetty create a UserTransaction for me.

    <build>
        <plugins>
            . . .
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.9</version>
                <configuration>
                    <scanIntervalSeconds>30</scanIntervalSeconds>
                    <webAppSourceDirectory>
                        ${project.build.directory}/${project.build.finalName}
                    </webAppSourceDirectory>
                    <!-- jettyEnvXml only works with jetty:run, 
                          but not jetty:run-war -->
                    <jettyEnvXml>
                        src/test/resources/jetty-env.xml
                    </jettyEnvXml>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>commons-logging</groupId>
                        <artifactId>commons-logging</artifactId>
                        <version>1.1</version>
                    </dependency>
                    <dependency>
                        <groupId>log4j</groupId>
                        <artifactId>log4j</artifactId>
                        <version>1.2.13</version>
                    </dependency>
                    <dependency>
                        <groupId>jotm</groupId>
                        <artifactId>jotm</artifactId>
                        <version>2.0.10</version>
                    </dependency>
                    <dependency>
                        <groupId>javax.resource</groupId>
                        <artifactId>connector</artifactId>
                        <version>1.5</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

And here’s how my src/test/resources/jetty-env.xml looks like.

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
  "http://jetty.mortbay.org/configure.dtd">

<Configure class="org.mortbay.jetty.webapp.WebAppContext">

  <!-- Ensure Jetty Plus features are enabled for this webapp -->
  <Set name="configurationClasses">
    <Array type="java.lang.String">
      <Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
      <Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
      <Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
      <Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>
      <Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item>
    </Array>
  </Set>

  <New id="jotm" class="org.objectweb.jotm.Jotm">
    <Arg type="boolean">True</Arg>
    <Arg type="boolean">False</Arg>
    <Call id="ut" name="getUserTransaction"/>
    <Call id="tm" name="getTransactionManager"/>
  </New>
  <Call name="setAttribute">
    <Arg>txmgr</Arg>
    <Arg><Ref id="tm"/></Arg>
  </Call>
  <New class="org.mortbay.jetty.plus.naming.Resource">
    <Arg>javax.transaction.TransactionManager</Arg>
    <Arg><Ref id="ut"/></Arg>
  </New>
  <New id="tx" class="org.mortbay.jetty.plus.naming.Transaction">
    <Arg><Ref id="ut"/></Arg>
  </New>

</Configure>

Boy, the above took me about two (2) days to get it working. I’m not even sure if it’s the best of way of doing it! All I know is that LCDS Assemblers need to access a UserTransaction (JTA) via JNDI (just like the tomcat that comes bundled with the LCDS 2.6 beta 2 download). If you have an easier way to make it work with the Maven Jetty plugin, please let me know.

I also found out that I can set <use-transactions> to false in the data-management-config.xml file in the config module. But remember to re-build the ria module to pick up the new config settings. With <use-transactions> set to false, a UserTransaction is no longer required. It expects that the DAOs will do its own transaction handling.

Note that I had to package the web app first (to get all the xml and swf files into a folder under target) before using Jetty plugin. So I’m doing a mvn clean package jetty:run to test if the web app works. So far, it’s working fine.

In my next post, I’ll move the DAOs and entity classes into a separate module. I’ll use Hibernate annotations (instead of JDBC) to re-write the DAOs and entity classes. I want to use hbm2ddl in my Maven build to create the database schema.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: