0 Replies Latest reply on May 28, 2010 2:41 AM by Improving_Flex

    flex 4, BlazeDS, ANT task issue

    Improving_Flex

      Hi,

       

      I want to compile flex 4 application using ANT mxmlc task. My application's front end was developed using flex 3. I am using Java at the back end and BlazeDS as the message broker between front-end (flex) and back-end (java). BlazeDS configuration is defined using spring injection.

       

       

      Following was the ANT script which was compiling the application correctly using flex 3.

       

      <property file="${basedir}/build.properties"/>

      <property name="FLEX_HOME" value="${env.FLEX_HOME}" />

      <property name="flex.src.dir" value="${basedir}/src/main/flex"/>

      <property name="flex.app.file" value="index.mxml"/>

      <property name="flex.output.dir" value="${basedir}/WebContent"/>

      <property name="flex.output.file" value="index.swf"/>

      <property name="flex.config.dir" value="${basedir}/src/main/resources/flex"/>

      <property name="flex.assets.dir" value="${flex.src.dir}" />

      <property name="flex.lib.dir" value="${basedir}/libs" />

      <property name="debug" value="false" />


      <!-- Define the Flex tasks. -->

      <taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar"  />


      <target name="compile.flex">

      <mxmlc newenvironment="true"

      file="${flex.src.dir}/${flex.app.file}"

      output="${flex.output.dir}/${flex.output.file}"

      optimize="true"

      context-root="/hrms-web"

      debug="${debug}"

      >

      <arg id="services" value="${flex.config.dir}/services-config.xml" />

      <arg id="locale" value="en_US" />

      <arg id="source-path" value="${flex.src.dir}/assets/locale/{locale}" />

      <arg id="allow-source-path-overlap" value="true" />

      <arg id="incremental" value="true" />


      <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />

       

      <!-- List of path elements that form the roots of ActionScript class hierarchies. -->

      <source-path path-element="${flex.src.dir}" />

      <source-path path-element="${flex.src.dir}/assets/locale/{locale}" />

      <source-path path-element="${FLEX_HOME}/frameworks" />

      <compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">

      <include name="libs" />

      <include name="locale/{locale}" />

      <include name="libs/player/10/**" />

      </compiler.library-path>

       

      <!-- List of SWC files or directories that contain SWC files. -->

      <library-path dir="${flex.lib.dir}" append="true">

      <include name="*.swc" />

      </library-path>

      </mxmlc>

      </target>

       

       

      After I installed flex 4 and used some components of flex 4, I installed Flash Builder 4 which compiles the swf correctly. Following are the screen shots of the flex configuration in Flash Builder 4.

       

      Flex Applications.png

       

      Flex Build Path.png

      Flex Build Path 2.png

      Flex Compiler.png

      Flex Modules.png

      Flex Server.png

      Flex Theme.png

       

      I used the same old ANT script, obviously with new (flex 4) library files (mxmlc.jar, blazeDS jars etc), to compile flex application using flex 4 sdk. It does compile and generate an swf file, but this file's size is less than half of the one generated by flash builder. Also, when I deploy this file in web server, it does load, but is unable to connect to remote destinations.

       

      Here is the ANT script and error message.

       

      <property file="${basedir}/build.properties"/>

      <property name="FLEX_HOME" value="${env.FLEX_HOME}" />

      <property name="flex.src.dir" value="${basedir}/src/main/flex"/>

      <property name="flex.app.file" value="index.mxml"/>

      <property name="flex.output.dir" value="${basedir}/WebContent"/>

      <property name="flex.output.file" value="index.swf"/>

      <property name="flex.config.dir" value="${basedir}/src/main/resources/flex"/>

      <property name="flex.assets.dir" value="${flex.src.dir}" />

      <property name="flex.lib.dir" value="${basedir}/libs" />

      <property name="debug" value="false" />


      <!-- Define the Flex tasks. -->

      <taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar"  />


      <target name="compile.flex">

      <mxmlc newenvironment="true" description="Compiles the flex project into an swf fille."

      file="${flex.src.dir}/${flex.app.file}"

      output="${flex.output.dir}/${flex.output.file}"

      optimize="true"

      context-root="hrms-web"

      debug="${debug}"

      >

       

      <arg id="services" value="${flex.config.dir}/services-config.xml" />

      <arg id="locale" value="en_US" />

      <arg id="source-path" value="${flex.src.dir}/assets/locale/{locale}" />

      <arg id="allow-source-path-overlap" value="true" />

      <arg id="theme" value="${FLEX_HOME}/frameworks/themes/Halo/halo.swc" />

      <arg id="strict" value="true" />

      <arg id="verbose" value="true" />

      <!--arg id="compatibility-version" value="3.0" />

      <arg id="incremental" value="false" />

      <arg id="append" value="true" />

      <arg id="context-root" value="hrms-web" /-->


      <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />


      <!--classpath>

      <fileset dir="${web.services.config.dir}">

      <include name="*.xml" />

      </fileset>

      </classpath>

       

      <classpath>

      <fileset dir="${flex.config.dir}">

      <include name="*.xml" />

      </fileset>

      </classpath -->

       

      <!-- List of path elements that form the roots of ActionScript class hierarchies. -->

      <source-path path-element="${flex.src.dir}" />

      <source-path path-element="${flex.src.dir}/assets/locale/{locale}" />

      <source-path path-element="${FLEX_HOME}/frameworks" />

      <compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">

      <include name="libs" />

      <include name="locale/{locale}" />

      <include name="libs/player/10/**" />

      </compiler.library-path>


      <!-- List of SWC files or directories that contain SWC files. -->

      <library-path dir="${flex.lib.dir}" append="true">

      <include name="*.swc" />

      </library-path>

      </mxmlc>

      </target>

       

       

      Here is services-config.xml

       

      <?xml version="1.0" encoding="UTF-8"?>

      <services-config>


      <services>

       

      <service-include file-path="remoting-config.xml" />

      <service-include file-path="proxy-config.xml" />

      <service-include file-path="messaging-config.xml" />

       

      <default-channels>

      <channel ref="my-amf"/>

      </default-channels>

       

      </services>


      <channels>

      <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">

      <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>

      <properties>

      <polling-enabled>false</polling-enabled>

      </properties>

      </channel-definition>


      <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">

      <endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>

      <properties>

      <add-no-cache-headers>false</add-no-cache-headers>

      </properties>

      </channel-definition>

      </channels>

      <logging>

      <!-- You may also use flex.messaging.log.ServletLogTarget -->

      <target class="flex.messaging.log.ConsoleTarget" level="Warn">

      <properties>

      <prefix>[BlazeDS] </prefix>

      <includeDate>false</includeDate>

      <includeTime>false</includeTime>

      <includeLevel>true</includeLevel>

      <includeCategory>false</includeCategory>

      </properties>

      <filters>

      <pattern>Endpoint.*</pattern>

      <pattern>Service.*</pattern>

      <pattern>Configuration</pattern>

      </filters>

      </target>

      </logging>


      <system>

      <redeploy>

      <enabled>true</enabled>

      <watch-interval>20</watch-interval>

      <watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-file>

      <watch-file>{context.root}/WEB-INF/flex/remoting-config.xml</watch-file>

      <touch-file>{context.root}/WEB-INF/web.xml</touch-file>

      </redeploy>

      </system>


      </services-config>

       

      Here is my remoting-config.xml

       

      <?xml version="1.0" encoding="UTF-8"?>

      <service id="remoting-service"

      class="flex.messaging.services.RemotingService">


      <!-- This is default adaptor for flex/BlazeDS requests -->

      <adapters>

      <adapter-definition id="java-object"

      class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>

      </adapters>


      <!-- This is default channel for flex/BlazeDS requests -->

      <default-channels>

      <channel ref="my-amf"/>

      </default-channels>


      </service>

       

      My destinations (services) are defined in another spring configuration file. Here are the contents of that file:

       

      <beans xmlns="http://www.springframework.org/schema/beans"

      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

      xmlns:flex="http://www.springframework.org/schema/flex"

      xmlns:p="http://www.springframework.org/schema/p"

      xmlns:context="http://www.springframework.org/schema/context"

      xmlns:security="http://www.springframework.org/schema/security"

      xsi:schemaLocation="http://www.springframework.org/schema/beans

      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

      http://www.springframework.org/schema/context

      http://www.springframework.org/schema/context/spring-context-2.5.xsd

      http://www.springframework.org/schema/flex

      http://www.springframework.org/schema/flex/spring-flex-1.0.xsd

      http://www.springframework.org/schema/security

      http://www.springframework.org/schema/security/spring-security-2.0.4.xsd

      ">

      <import resource="applicationContext.xml" />


      <bean id="mySpringFlexExceptionTranslator"

      class="net.hrms.web.util.SpringFlexExceptionTranslator"/>


      <flex:message-broker services-config-path="/WEB-INF/flex/services-config.xml">

       

      <flex:exception-translator ref="mySpringFlexExceptionTranslator"/>

       

      <flex:remoting-service default-adapter-id="my-default-remoting-adapter"

      default-channels="my-amf, my-secure-amf" />

      <flex:secured />

       

      </flex:message-broker>


      <flex:remoting-destination ref="mappingService"/>

      <flex:remoting-destination ref="searchUIService"/>

      <flex:remoting-destination ref="lookupUIService"/>

      <flex:remoting-destination ref="documentUIService"/>

      <flex:remoting-destination ref="listUIService"/>

      <flex:remoting-destination ref="activityUIService"/>

      </beans>

       

       

      Here are the snap shots of error messages that pop up when I use the generated swf.

       

      ErrorMessage.png

       

      ErrorMessage2.png

       

       

      Any one can please help?