flex eclipse blazeds环境筹建实例

flex eclipse blazeds环境搭建实例

Java5.0,tomcat5.5,eclipse 3.2(及以上),myeclipse(5.5及以上),FB3_WWEJ_Plugin.exe等等,按顺序都把他们先装上,然后myeclipse里面配置好tomcat这个就不详细说了。然后去下载个blazeds,这个自己去搜索吧!

blazeds与web工程的搭建:myeclipse中先创建个web项目myflex,注意要导入blazeds里面的相关jar,web.xml,还有WEB-INF里面flex目录下面的所有文件。最好的操作方法是,先把blazeds解压,然后再新建的工程里面WebRoot à右键à import à File System à next à 选择你解压后的blazeds目录,finish。这样会有提示是否要覆盖,点yes to all就OK了。

接下来在服务器端可以简单的写个helloWorld的类了,相关的配置弄好

package com.spell;

publicclass 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了,并且启动tomcat,这个时候不要着急着去测试

flex工程的搭建:这个是最让人恼火的地方了,这个地方上我走了很多的弯路,看那了网络上很多人所谓的配置,结果差点把我给搞死。后来还是自己的思路清晰点。

建个flex工程,输入工程的名称flexTest,application type 选择 web application, server technology 选择none,点next,output folder 中选择你上面建立web工程的目录(这里就是myflex了),这个很重要了,要不这边flex就不会自动到web工程了,那只有人工的拷贝了,这样做是很悲哀滴!!最后finish,好了这样flex工程也好了

flexTest.mxml文件
------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml " layout="absolute">
<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>

这个文件好了后,你只要保存下就可以敲入URL测试了(保存后马上就output到myflex项目中了,然后又自动同步到tomcat,前面tomcat已经启动了),我的是http://localhost:8080/myflex/flexTest.html ,表单中输入名字,然后点下按钮,就跟你说hello了,是不是很兴奋了,恭喜flex你入门了。这里一定要指定endpoint,要不然与服务器的交互会失败,endpoint的/myflex根据你web项目的名称不同而不同。endpoint不要指定死,如:http://localhost:8080/myflex/messagebroker/amf ,这样到了以后部署的时候是会有错误的。