我們要實(shí)現(xiàn)的目的:
1.希望在myeclipse里面可以創(chuàng)建flex項(xiàng)目。
2.在flex中編輯的mxml文件,保存后能夠自動(dòng)的生成flash文件和html文件以供測(cè)試,當(dāng)然正式發(fā)布的時(shí)候很多的HTML是要?jiǎng)h除的。
3.利用myeclipse在工程中實(shí)時(shí)同步機(jī)制,把我們編譯后的flash和html文件直接同步到web工程,然后工程自動(dòng)部署到tomcat,這樣測(cè)試就很方便了,因?yàn)橥絝lash和html文件到tomcat根本就不用重新啟動(dòng)。
注意我們的關(guān)鍵點(diǎn)本質(zhì)上只是把flex項(xiàng)目的編譯輸出直接到web工程。
好了,現(xiàn)在開始準(zhǔn)備工具:
環(huán)境搭建: Java5.0,tomcat5.5,eclipse 3.2(及以上),myeclipse(5.5及以上),F(xiàn)B3_WWEJ_Plugin.exe等等,按順序都把他們先裝上,然后myeclipse里面配置好tomcat這個(gè)就不詳細(xì)說了。然后去下載個(gè)blazeds,這個(gè)自己去搜索吧!(我的附件里面有)
blazeds與web工程的搭建: myeclipse中先創(chuàng)建個(gè)web項(xiàng)目myflex,注意要導(dǎo)入blazeds里面的相關(guān)jar,web.xml,還有WEB-INF里面flex目錄下面的所有文件。最好的操作方法是,先把blazeds解壓,然后再新建的工程里面WebRoot -> 右鍵 -> import -> File System -> next -> 選擇你解壓后的blazeds 目錄, finish。這樣會(huì)有提示是否要覆蓋,點(diǎn)yes to all就OK了。
接下來在服務(wù)器端可以簡(jiǎn)單的寫個(gè)helloWorld的類了,相關(guān)的配置弄好
package com.spell;
public class HelloWorld {
public String sayHello(String name) {
return "hello," + name;
}
}
在 WebRoot/WEB-INFO/remoting-config.xml 中加入 id="Hello" 的 destination
<destination id="Hello">
<properties>
<source>com.spell.HelloWorld</source>
</properties>
</destination>
ok,可以部署到tomcat了,并且啟動(dòng)tomcat,這個(gè)時(shí)候不要著急著去測(cè)試
flex工程的搭建: 這個(gè)是最讓人惱火的地方了,這個(gè)地方上我走了很多的彎路,看那了網(wǎng)絡(luò)上很多人所謂的配置,結(jié)果差點(diǎn)把我給搞死。后來還是自己的思路清晰點(diǎn)。
建個(gè)flex工程,輸入工程的名稱flexTest,application type 選擇 web application, server technology 選擇none,點(diǎn)next,output folder 中選擇你上面建立web工程的目錄(MyEclipse里就是myflex工程目錄下的WebRoot了), 這個(gè)很重要了,要不這邊f(xié)lex就不會(huì)自動(dòng)到web工程了,那只有人工的拷貝了,這樣做是很悲哀滴!!最后finish,好了這樣flex工程也好了
flexTest.mxml文件
------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
<mx:Script >
<![CDATA[ import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
[Bindable]
private var helloResult:String;
private function sayHello():void {
ro.sayHello(inputText.text);
}
private function resultHandler(event:ResultEvent):void {
helloResult = event.result as String;
}
]]>
</mx:Script >
<mx:RemoteObject id="ro" destination="Hello" result="resultHandler(event)"
endpoint="/myflex/messagebroker/amf" />
<mx:HBox x="0" y="10" width="100%">
<mx:Label text="Name:" id="nameLabel"/>
<mx:TextInput id="inputText"/>
<mx:Button label="say Hello" id="nameButton" click="sayHello()"/>
<mx:Label id="resultLabel" text="{helloResult}"/>
</mx:HBox>
</mx:Application>
這個(gè)文件好了后,你只要保存下就可以敲入U(xiǎn)RL測(cè)試了(保存后馬上就output到myflex項(xiàng)目中了,然后又自動(dòng)同步到tomcat,前面tomcat已經(jīng)啟動(dòng)了),我的是http://localhost:8080/myflex/flexTest.html ,表單中輸入名字,然后點(diǎn)下按鈕,就跟你說hello了,是不是很興奮了,恭喜flex你入門了。這里一定要指定endpoint, 要不然與服務(wù)器的交互會(huì)失敗,endpoint的/myflex根據(jù)你web項(xiàng)目的名稱不同而不同。endpoint不要指定死,如:http://localhost:8080/myflex/messagebroker/amf ,這樣到了以后部署的時(shí)候是會(huì)有錯(cuò)誤的。
轉(zhuǎn)自:http://holdbelief.javaeye.com/blog/227394