专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Flex

flex java调整

发布时间:2011-06-27 19:26:39 文章来源:www.iduyao.cn 采编人员:星星草
flex java整合
[转自:http://hi.baidu.com/duqian1985/blog/item/bb3bdf062fe95a73020881dd.html]

step 1.下载 flex 3.0 plugin 插件 装在 我的myeclipse 6.0 上


   1) 下载地址:http://trials.adobe.com/Applications/Flex/FlexBuilder/3/FB3_WWEJ_Plugin.exe

   2)安装插件

    将flex plugin 安装目录里面的com.adobe.flexbuilder.update.site 文件夹下面的features 文件夹,plugins 文件夹 和 site.xml 文件 添加在myeclipse 文件夹的eclipse文件夹内.

              将 flex plugin 安装目录里面的eclipse 文件夹下面的features 文件夹,plugins 文件夹 覆盖在myeclipse 文件夹的eclipse文件夹内.(防止更新)

step1 完



step 2.下载 blazeds

http://download.macromedia.com/pub/opensource/blazeds/blazeds_bin_3-0-0-544.zip

解压之后是个 blazeds. war包,把它放在tomcat 的webapp里面 部署一下就会释放出来一个类似与工程文件的东西(里面就有将flex 和java 合并的重要文件)

step 2 完

step 3 . 合并 web project 和flex 工程


新建一个web project 工程

把 blazeds.war 部署之后的 flexweb 文件夹里面的lib 目录copy 到 web-inf 的lib目录里

把 blazeds.war 部署之后的 flexweb 文件夹里面的flex 目录copy 到 web-inf 下面

替换 web.xml 这步很重要,容易忘记,忘记你就死定了,慢慢调去吧!

都加完了把? 这时候把web project 工程部署在tomcat上面上他跑起来, 之后在加入flex ,单击工程右键flex project natrue --- > add flex project natrue

第一步见下图




第二步见下图




都整完了看一下配置是否正确,正确就可以进行 step 4了。

step 3 完


step 4 . 让flex调用java类(这tm才是我们想要到达的目的!)

在src 里面见一个包,包里面见一个类 包名.类名 whatever

开始配置 remoting-config.xml

在里面加入

    <destination id="hello">
         <properties>
             <source>com.Hello</source>
        </properties>
    </destination>

hello 是别名

com.hello 是类的全路径

然后配置services-config.xml(这个tm那个介绍配置上面也没写,你说你到是告诉一声啊,向我们这种粗心大意的人那在乎啊,就因为这个没配置我就浪费了2个小时,我只能对那些网上发帖子教人家配置的大牛们,说一声:"大哥在说的详细点被")

        <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://127.0.0.1/flexweb/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint" />
   
        </channel-definition>

        <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
            <endpoint url="https://127.0.0.1/flexweb/messagebroker/amfsecure " class="flex.messaging.endpoints.SecureAMFEndpoint"/>
            <properties>
                <add-no-cache-headers>false</add-no-cache-headers>
            </properties>
        </channel-definition>

        <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://127.0.0.1/flexweb/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
            <properties>
                <polling-enabled>true</polling-enabled>
                <polling-interval-seconds>4</polling-interval-seconds>
            </properties>
        </channel-definition>

主要就是把那个 url 改成自己的工程 路径,太tm 重要了!

step 4 完


使用 :

写一个hello类

public class Hello {
    public String hello(String name){
        System.out.println(name);
        return "hello"+name;
    }
}

一个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.ResultEvent;
function gg(evnet:ResultEvent):void{
var ff:String = evnet.result as String;
ggg.text = ff;
}
function remotingSayHello():void{
var sname:String = nameInput.text;
h.hello(sname);
}
]]>
</mx:Script>
<mx:RemoteObject destination="hello" id="h"
result="gg(event)" endpoint="http://127.0.0.1/flexweb/messagebroker/amf" >
</mx:RemoteObject>
<mx:TextArea id="ggg" x="109" y="122"/>
<mx:Button label="say hello" click="remotingSayHello();" x="144" y="193"/>
<mx:TextInput id="nameInput" x="109" y="73"/>
<mx:Label text="name" x="47" y="75"/>
</mx:Application>


接着整合spring
1)新增一个配置文件flex-servlet.xml,内容如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:flex="http://www.springframework.org/schema/flex"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="
     http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/flex
     http://www.springframework.org/schema/flex/spring-flex-1.5.xsd">
    
<flex:message-broker/>
<flex:remoting-destination ref="userService"/>

</beans>

2)web.xml
将上文中MessageBrokerServlet 的部分用以下替换
<servlet>
<servlet-name>flex</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
           /WEB-INF/flex/flex-servlet.xml
            </param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

    <!-- Servlet Mapping 配置-->
<servlet-mapping>
<servlet-name>flex</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>


此时,WEB-INF/flex目录下除了flex-servlet.xml、services-config.xml文件皆可删除
原因尚待研究。。。
flex-servlet.xml引用spring中的bean
services-config.xml用于flex文件编译时请求路径的获取
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: