问题重现:
在使用 maven flexmojos plugin 开发 felx项目过程中,执行 flexmojos:compile-swf + flexmojos:wrapper 后运行页面,尝试与后台交互,遇到如下异常信息:
[RPC Fault faultString="[MessagingError message='Destination 'yourRemoteService' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']" faultCode="InvokeFailed" faultDetail="Couldn't establish a connection to yourRemoteService'"]
问题原因:
需要在 flex 项目 pom.xml 中,正确配置如下参数:
1) <rootURL/>
访问远程 server 的 URL
2) <contextRoot/>
上下文路径
3) <services/>
BlazeDS 的 services-config.xml 文件位置
贴出完整 pom.xml:
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <artifactId>ria-flexClient</artifactId> <groupId>ria</groupId> <version>1.0-SNAPSHOT</version> </parent> <groupId>ria</groupId> <artifactId>client-portal</artifactId> <version>1.0-SNAPSHOT</version> <packaging>swf</packaging> <name>client-portal Flex</name> <dependencies> <!--flex SDK--> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>flex-framework</artifactId> <version>${flex.framework.version}</version> <type>pom</type> </dependency> <!--unit test--> <dependency> <groupId>com.adobe.flexunit</groupId> <artifactId>flexunit</artifactId> <version>${flexunit.version}</version> <type>swc</type> <scope>test</scope> </dependency> <!--cairngorm MVC 框架--> <dependency> <groupId>com.adobe.flex</groupId> <artifactId>cairngorm</artifactId> <version>${flex.framework.cairngorm.version}</version> <type>swc</type> </dependency> </dependencies> <build> <sourceDirectory>src/main/flex</sourceDirectory> <testSourceDirectory>src/test/flex</testSourceDirectory> <plugins> <!--flexmojos 插件--> <plugin> <groupId>org.sonatype.flexmojos</groupId> <artifactId>flexmojos-maven-plugin</artifactId> <version>${flexmojos-maven-plugin.version}</version> <extensions>true</extensions> <dependencies> <dependency> <groupId>com.adobe.flex</groupId> <artifactId>compiler</artifactId> <version>${flexmojos-maven-plugin.compiler.version}</version> <type>pom</type> </dependency> </dependencies> <configuration> <!--build 完成后自动生成 configuration Report , flexmojos 必要文件--> <configurationReport>true</configurationReport> <!--指定flash player版本 最低9.0.0--> <targetPlayer>${flex.targetPlayer.version}</targetPlayer> <!--密钥 留空--> <storepass/> <!--编译时读取 source 的目录 ,默认 src/main/flex --> <sourcePaths> <path>${build.sourceDirectory}</path> </sourcePaths> <!--需要编译的文件, 即 default application --> <sourceFile>Portal.mxml</sourceFile> <!--html wrapper 文件名称--> <htmlName>Portal</htmlName> <!--生成可debug的swf文件,默认false--> <debug>false</debug> <!--compiler.locale--> <locales> <locale>en_US</locale> </locales> <!--对 swf 进行后期优化, 默认true--> <optimize>true</optimize> <!--以增量方式编译,默认false--> <incremental>false</incremental> <!--编译时显示 warning,默认true --> <showWarnings>true</showWarnings> <!-- 严谨编译,默认true--> <strict>true</strict> <!--swf 可连接 network--> <useNetwork>false</useNetwork> <!-- 访问 server 的 URL --> <rootURL>http://localhost:8888/</rootURL> <!-- 上下文路径 --> <contextRoot>/</contextRoot> <!--BlazeDS 的 services-config.xml 文件位置--> <services>${flex.services.path}</services> <!--输出 swf 的路径加文件名 --> <output>${client.deploy.path}/${project.build.finalName}.swf</output> <!--编译输出文件的路径 --> <outputDirectory>${client.deploy.path}</outputDirectory> <!--指定一个配置文件,包含以上所有设定的参数,默认在 resources 下找 flex-config.xml--> <!--<configFile>target/classes/configs/flex-config.xml</configFile>--> </configuration> </plugin> </plugins> </build> </project>
这三个参数与 FlashBuilder4 下,通过 J2EE Server(BlazeDS)配置的参数是一致的,贴图如下:
简单说就是:同样的参数,配置的地方不同。flexmojos 在 pom.xml,而 flashBuilder4 是在 Flex Server 选项卡。
另外:
1)发布 swf 时,推荐使用 flexmojos optimize:true + debug:false,一般可使编译后的swf文件减肥到原来大小的 40%~50%,意味着加载和打开的速度更快。
2)推荐在命令行下执行 mvn 指令,如果在 IDE 环境下运行 mvn 指令出现 compile 失败,可能是默认JRE 是 java sdk,手动更正下就行。
