問題重現:
在使用 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:
這三個參數與 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,手動更正下就行。