版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Flex + LCDS + Java 入门教程一引很多人在帖子和群中问到过一些关于建立Flex+LCDS(FDS)工程的问题,由于操作上的东西,很难简单说清楚,于是写了一个简单的教程(本来很早就答应过的,结果被newfish逮住做东西,加上公司的事,一直抽不出时间哈,现在想换换头脑,偷乐一下懒哈,各位别跟newfish大大说),帮助大家入门,其实这些东西都是在LCDS的sample中包含了的(当然,sample只是包含源码)。本教程通过图文介绍和对一些关键性的地方进行解释,让大家了解如何新建Flex的LCDS工程,并利用工具快速整合和部署J2EE项目和LCDS项目,掌握了简单的请求Remote
2、Object和配置的方法,初步掌握LCDS的应用之一。二介绍1.Flex是什么?2. LCDS是什么?LCDS(LiveCycle Data Service)之前叫做FDS(Flex Data Service),他是基于java(也有ColdFusion版的)后端的数据服务工程,功能包括映射Java对象到Flex对象(包括调用Java类的方法)、RTMP(Real Time Message Protocol)、代理、服务端生成PDF等等功能,详细请参考LCDS里的说明。官方有下载,需要注册会员(免费)。LCDS实际是付费的,但是免费也能使用,似乎是少了多CPU的支持。当然还有一些其他的数据服务
3、,比如AMFPHP之类的。当然,LCDS提供的功能我们都能自己实现,并非Flex脱离了LCDS就不能和后台打交道了,除了RemoteObject还有WebSerivce、HTTPService等等。只是说,LCDS提供了更多的方便和特性。3. Java是什么?三准备1.下载开发环境:Eclipse 3.3 + FlexBuilder3 beta2 插件版 +MyEclipse 6.0 +Lcds + Tomcat 5和以上(官方都有下载,或者google里搜一搜哈)MyEclipse:做Java开发都应该知道MyEclipse是比较好的J2EE项目的开发及部署工具的,我们主要用它来部署Flex
4、和Java结合的项目。6.0是适合Eclipse3.3版的。他自带了一个Tomcat服务器FB3:相比FB2,他在LCDS工程上做了很大的改进,特别是beta2,项目向导更加的易懂,而且比FB2更好的是,Flex.war是被打包在你的Flex项目中的,而不需要单独的部署了。性能上也高出FB2LCDS:安装lcds后,起作用的是里面的flex.war文件,实际上,这就是一个j2ee的工程。在发布到web应用服务器后(比如tomcat、j4run等)就会被解压成一个工程。当然,在FB3里,这个发布的过程会更加的简单。2.安装:略四入门教程1.新建FlexLCDS工程File - new - Fle
5、x Project 注:以下设置绝大多数都可以在项目属性中可以修改。1).向导界面1说明:Java source folder就是你自己java业务源码存放的根目录,在FB3里,LCDS项目旨在将Java J2ee项目和FlexLcds项目混合。当然如果你不选择 combined 两个在一起,那么就麻烦些:要么你再单独新建一个Flex项目,而这个项目只写java代码。要么再建一个J2ee工程写java代码,而这个项目只写Flex代码,但最后要把Java编译后的class文件放到这个项目下的webrootweb-infclasses目录中。即不管怎样,最后发布时,java编译后的class文件必
6、须和lcds部署的项目在一起。(听起来绕昏头了?那就在一个工程里吧)2).向导界面2说明:Target runtime实际上没什么用(后来我删除了配置文件里的对应信息,也没问题),但是不指定就不能继续,如果这里显示的是那么就新建一个Tomcat的runtime,简单的只需要指定tomcat的安装目录即可。Content folder实际上就是最终编译后的容器目录,因此,Lcds的flex.war文件将会发布到 该目录 下的web-inf下的flex目录中。同时因为教程采用的是MyEclipse,他默认的就是发布WebRoot里的内容,为了自动化,因此这里改为了WebRoot(这也是java开发
7、的习惯) Flex WAR file 指的是安装了lcds后的flex.war文件的路径Compilation options指定了flex文件的编译方式,选择推荐的在FlexBuilder里编译吧,虽然开发时多耗点时间,但是在发布后不会占用服务器的编译处理时间,对用户来说是有好处的。Output folder 指的是Flex编译后的swf和html等文件存放的路径,这里改为了WebRootbin3).向导界面3说明:Main source folder 是flex的源码存放根目录,当然和java源码分开了。Output folder URL 是在开发过程中运行和调试的请求路径,这个与发布无关
8、,不会影响任何你在程序中使用的路径,但是能使开发方便注意:FlexBuilder3这里存在bug,新建工程时,部分自定义的属性并没有保存下来,而必须在新建后的项目属性中更改,后面有说明到放心这些设置都可以在以后修改。4).新建完成的项目结构看起来是这样的2.用MyEclipse添加Web容器之前说到了,MyEclipse是很好用的J2EE的开发插件,其中就包含了部署功能。我们可以抛开烦琐的手动部署,交由MyEclipse完成吧,当然,首先得让你的FlexLCDS工程变成为J2EE的Web工程。1).向导界面1注意:不要点快了,把这里的Create web.xml取消,这样就不会覆盖LCDS创建
9、的web.xml文件现在我们的工程的图标变成了J2EE Web 工程了,这意味着,你可以用MyEclipse来发布它或者添加更多容器,比如hibernate、spring等3. 部署FlexLCDS工程有了MyEclipse,那么你就不用手动的部署你的项目了,可以简单的通过点击工具栏上的这个图标1).部署向导1注意:(如果你的列表中没有服务器,那么就自己建一个)2).新建部署Web应用服务器注意:如果是MyEclipse6.0,则会自带一个Tomcat服务器。如果不是6.0,那么点Edit server connectors自己添加一个tomcat。点finish后则会开始部署。成功后会在De
10、ployment status里提示success,并且看到列表中你的项目已经成功部署4. 修改一下项目的访问路径打开项目的属性,在这里,我们可以重新修改项目编译和发布的配置,包括先前向导里的设置修改output folder url为什么要这么做?这样每次发布都会自动将编译的最终swf文件直接发布至WebRootbin目录下,而下面的output folder url则会在我们启动和调试项目时,直接请求这个路径(这跟发布无关,只是我们在开发过程中会方便些)5. 修改Flex Server的项目容器属性(非常重要,多数连接路径错误就是这里配置错误)改成如下配置说明:Root url 当然就是你
11、的web服务器的根路径了,Tomcat默认是8080端口,如果改了就自己修改Context root 就是LCDS工程的名称(注意:如果你分开为两个工程,则这里指的是你J2ee项目的名称,而不是你Flex项目的名称,因为你在请求Java的数据服务),在Flex请求LCDS时,会采用这个作为参数:server.port/context.root/messagebroker/amf如果Context root错了,那么永远不可能正确的请求LCDS的服务了。确定后,我们来运行测试一下这个FlexLCDS项目是否能正常访问6. 启动服务器稍等片刻,等到服务器完全启动后
12、继续下面的操作7. 运行访问注:如果之前的Output folder url配置正确,那么会自动的弹出访问页面,DEBUG时也是一样。OK,一切顺利,至此,你已经做到了第一步,即,将Flex项目、LCDS服务成功的整合至J2EE web 项目,这样的好处就是今后发布省的麻烦了。五简单的RemoteObject1.什么是RemoteObject?顾名思义,即远程对象。这里指的就是在Flex中获取Java里的对象。有什么用呢?这样Flex可以更加简单的获取服务端的数据,比如你在Java中有个方法进行了数据查询,取出的结果是Array类型,那么你可以很容易通过Flex里的RemoteObject访问
13、到该类,并调用该方法,最后返回的数据是Flex也兼容的Array对象。2. 新建Java类File - new -other(如果你没在列表中看到java class的话)1).新建向导12).向导2注意:别忘记了你设定的java源码根目录路径,如果对java不熟悉的话,这里我就不解释了,照着做吧。3).编写如下代码package com.test;public class FirstJavaClass public String sayHello(String str)return 你说的是:+str;3. 配置Flex LCDS的Remoting-config.xml1).他是remote
14、object和相关远程访问的配置文件,路径位于注意:现在LCDS是你的项目的一部分了,因此不用来回的在服务器中修改配置然后再发布了。2).改写其代码如下 com.test.FirstJavaClass application 说明:一个destination 指定的就是一个RO对象,他的id就是在Flex中RO请求的destination,source 指的是这个Java类的路径注意:在修改了配置文件后可能需要重启web服务器(Tomcat)4. 编写mxml来请求RO1).打开MyFirstLCDS.mxml编写代码如下2)OK,保存好后,用之前的方法来运行一下看看?RemoteObject
15、的简单教程完Flex +BDS + Java 入门教程 差别唯一就在选择flex.war的时候选择bds对应的warBDS+Spring/devnet/livecycle/articles/blazeds_spring.htmlGetting startedWhether you are a Flex developer with limited knowledge of Spring, or a Spring developer with limited knowledge of Flex, you can benefit from the powerf
16、ul integration of these products. This section describes how BlazeDS enables a tight integration between Flex and Spring, and provides background information on the technologies at play.What is Spring?Spring is one of the most popular Java frameworks. The foundation of the Spring framework is a ligh
17、tweight component container that implements the Inversion of Control (IoC) pattern. Using an IoC container, components dont instantiate or even look up their dependencies (the objects they work with). The container is responsible for injecting those dependencies when it creates the components (hence
18、 the term Dependency Injection also used to describe this pattern). The result is looser coupling between components. The Spring IoC container has proven to be a solid foundation for building robust enterprise applications. The components managed by the Spring IoC container are called Spring beans.T
19、he Spring framework includes several other modules in addition to its core IoC container. These modules are not covered in this document even though we will be using the Spring JDBC abstraction framework in the second sample application below. More information on the Spring framework can be found at
20、 .What is Flex?Flex is an environment for building Rich Internet Applications. The Flex programming model is made of: ActionScript, an ECMAScript compliant, object-oriented programming model. With some syntactical differences, ActionScript looks and feels similar to Java
21、, and supports the same object-oriented constructs: packages, classes, inheritance, interfaces, strong (but also dynamic) typing etc. MXML: an XML-based language that provides an abstraction on top of ActionScript, and allows parts of an application (typically the View) to be built declaratively. An
22、 extensive set of class libraries. The documentation is available here in a Javadoc-like format. The Flex source code (.mxml and .as files) is compiled into Flash bytecode (.swf) that is executed at the client-side by the Flash virtual machine using a Just-In-Time compiler.The Flex SDK is an open so
23、urce project. It includes the Flex component library, the compiler, the debugger, and the documentation. A complete discussion of Flex is beyond the scope of this document. You can find more information and download the Flex SDK at . What is BlazeDS?BlazeDS is a set of data
24、 services that give your Flex applications additional options for data connectivity. Without BlazeDS (or, without deploying any Flex-specific component at the server-side), Flex applications can access back-end data using either the HTTPService or the WebService: You use the HTTPService component to
25、 send HTTP requests to a server, and consume the response. Although the HTTPService is often used to consume XML, it can be used to consume other types of responses. The Flex HTTPService is similar to the XMLHttpRequest component available in Ajax. You use the WebService component to invoke SOAP-bas
26、ed web services. BlazeDS adds the following services: The Remoting Service allows your Flex application to directly invoke methods of Java objects deployed in your application server. The Message Service provides a publish/subscribe infrastructure that enables your Flex application to publish messag
27、es and subscribe to a messaging destination, enabling the development of real-time data push and collaborative applications. The Proxy Service allows your Flex application to make cross-domain service requests in a secure and controlled manner. In other words, it allows your Flex application to acce
28、ss a service available on a different domain than the domain from where the application was downloaded (without having to deploy a crossdomain.xml policy file on the target domain). BlazeDS is deployed as a set of JAR files as part of your web application. Like the Flex SDK, BlazeDS is an open-sourc
29、e project. More information is available at .In this document, we focus on the Remoting service. The Remoting Service provides a tight and natural integration with Spring. There is no need to transform data, or to expose services in a certain way: the Flex application can d
30、irectly access the beans registered in the Spring IoC container.How does Flex use BlazeDS to access Spring beans? So, if Flex clients can remotely access Java objects, and if Spring beans are Java objects, arent we all set and ready to start accessing Spring beans from Flex clients? Almost There is
31、one simple element to configure. The whole idea behind Spring IoC is to let the container instantiate components (and inject their dependencies). By default, however, components accessed remotely by a Flex client are instantiated by BlazeDS on the server. The key to the Flex/Spring integration, ther
32、efore, is to configure BlazeDS to let the Spring container take care of instantiating Spring beans. BlazeDS supports the concept of a factory to enable this type of custom component instantiation. The role of a factory is simply to provide ready-to-use instances of components to BlazeDS (instead of
33、letting BlazeDS instantiate these components). The supporting files available with this article include a factory class (SpringFactory) that provides BlazeDS with fully initialized (dependency-injected) instances of Spring beans. Note: The SpringFactory was developed by Jeff Vroom (Flex Data Service
34、s architect) and is also available on Adobe Exchange.The remainder of this article describes how to configure your web application to use BlazeDS and Spring, how to configure the Spring Factory, and how to put the pieces together and start invoking Spring beans from Flex applications. Setting up you
35、r environmentConfiguring your web application is simple and merely requires installing and registering the necessary components.Step 1: Install the BlazeDS turnkey serverThe BlazeDS turnkey server is a ready-to-use version of Apache Tomcat in which the Blaze data services have already been deployed
36、along with sample applications. The goal of the turnkey server is to give developers an easy way to run samples and tutorials out of the box.To install the BlazeDS turnkey server:1. Make sure that you have the JDK 1.5 or higher installed, and that you have a JAVA_HOME environment variable pointing t
37、o your Java Development Kit installation. 2. Download blazeds-turnkey-.zip. 3. Unzip blazeds-turnkey-.zip in /blazeds. Note.You can unzip blazeds-turnkey-.zip anywhere else. Just make sure you adjust the path in the instructions provided in this document accordingly.4. Start the samples database. a.
38、 Open a command prompt. b. Navigate to /blazeds/sampledb. c. Execute startdb.bat (Windows) or startdb.sh (Unix-based systems) 5. Start Tomcat. a. Open a command prompt. b. Navigate to /blazeds/tomcat/bin. c. Execute the following command: catalina run d. Access http:/localhost:8400/samples to make s
39、ure the installation is successful: you should see the BlazeDS samples home page. As an alternative to using the turnkey server, you could use one of the following options:1. Download blazeds-.war and deploy it in your own application server. Blazeds-.war is a blank web application configured to use
40、 the BlazeDS data services. Note: samples-.war includes everything included in blazeds.war, plus a series of samples. 2. Download blazeds-.war and merge its content in your own web application. The instructions in this document assume that you use the BlazeDS turnkey server. If you are using one of
41、the alternative options, you will have to adjust the instructions accordingly. Step 2: Install the Flex SDKYou need the Flex compiler to compile the client-side (Flex-side) of the sample applications discussed in this document. The Flex compiler is part of the Flex SDK. As a convenience, the Flex SD
42、K is available as part of the BlazeDS installation in blazeds/resources/flex_sdk/flex_sdk_3.zip. Note: The Flex SDK can also be downloaded at . It is also available as part of Flex Builder.To install the Flex SDK:You can skip this step if Flex Builder 3 is installed on your
43、 system.Unzip /blazeds/resources/flex_sdk/flex_sdk_3.zip in /flex_sdk_3. Note: You can unzip flex_sdk_3.zip anywhere else. Just make sure you adjust the path in the instructions provided in this document accordingly.Step 3: Install SpringNote: A complete discussion of the Spring installation process
44、 is beyond the scope of this article. Refer to for more information. The steps below describe a basic configuration that is sufficient for the purpose of this article.1. Download the Spring framework at /download (the version without depende
45、ncies is sufficient to complete the examples in this article).Note: The examples below have been developed and tested using Spring 2.x. However the integration approach described in this document (and the SpringFactory class) should work fine using Spring 1.2.8 (some of the examples might not work b
46、ecause they use Spring 2.x features).2. Unzip the downloaded file. 3. Locate spring.jar in the dist directory and copy the file to /blazeds/tomcat/webapps/blazeds/WEB-INF/lib 4. Open /blazeds/tomcat/webapps/blazeds/WEB-INF/web.xml and add the context-param and listener definitions as follows: contex
47、tConfigLocation/WEB-INF/applicationContext.xmlorg.springframework.web.context.ContextLoaderListener Step 4: Install the supporting files1. Download flex-spring.zip here 2. Unzip flex-spring.zip in /flex-spring Flex-spring.zip includes the Spring factory as well as the supporting files for the exampl
48、es below.Step 5: Register the Spring factory1. Copy SpringFactory.class and SpringFactory$SpringFactoryInstance.class from /flex-spring/factory/bin/flex/samples/factories to /blazeds/tomcat/webapps/blazeds/WEB-INF/classes/flex/samples/factories. 2. Register the Spring factory in /blazeds/tomcat/weba
49、pps/blazeds/WEB-INF/flex/services-config.xml: Example 1: Mortgage calculatorThis first application is intentionally simplistic to provide an uncluttered example of wiring Spring beans together and invoking them from a Flex application. Step 1: Examine the application source code1. Examine the Flex s
50、ource code:Open MortgageCalc.mxml located in /flex-spring/samples/mortgage/flex in a code editor to familiarize yourself with the application. The application enables the user to enter a mortgage amount. When the user clicks the Calculate button, the application obtains the value of the monthly paym
51、ent for that mortgage by invoking the calculate() method of the remote object identified by a logical name: mortgageService. mortgageService is mapped to a fully qualified Java class name in the remoting-config.xml file (see Step 3 below). 2. Examine the Java source code:Open RateFinder.java, SimpleRateFinder.java and Mortgage.java located in /flex-spring/samples/mortgage/java in a code editor. Notice that Mortgage has a dependency to a RateFinder object. Mortgage doesnt instantiate a RateFinder object itself, doesnt lookup up for a RateFinder object, and doesnt even know the exact type of th
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年湖北电力建设第一工程公司招聘笔试参考题库含答案解析
- 2025年度个人信用担保装修借款合同范本3篇
- 2025年个人金融理财产品投资合同4篇
- 2025年度油气输送钢管租赁合作合同2篇
- 2025年度个人农田科技种植项目合作协议4篇
- 2025版二手房免税托管与租赁一体化服务合同
- 2025版协议离婚全程法律服务及婚姻财产分割合同3篇
- 2025年度二零二五年度钢厂废钢再生产品销售合同2篇
- 2025版新能源电池生产承包经营合同示范文本3篇
- 2025-2030全球叉车机器人行业调研及趋势分析报告
- 春节拜年的由来习俗来历故事
- 2023年河北省中考数学试卷(含解析)
- 通信电子线路(哈尔滨工程大学)智慧树知到课后章节答案2023年下哈尔滨工程大学
- 《公路勘测细则》(C10-2007 )【可编辑】
- 皮肤恶性黑色素瘤-疾病研究白皮书
- 从心理学看现代家庭教育课件
- C语言程序设计PPT(第7版)高职完整全套教学课件
- 头颈外科临床诊疗指南2021版
- 大国重器北斗系统
- 网球运动知识教育PPT模板
- 防火墙漏洞扫描基础知识
评论
0/150
提交评论