Requisitos:
- Apache Tomcat 6 Instalado.
- Ambiente Java (JRE)
- Eclipse IDE/Flex Builder Instalado
- Sysdeo Eclipse Tomcat Launcher plugin Instalado.
- BlazeDS
1. Crie um projeto do tipo Dynamic Web Project em File> New> Other…> Web> Dynamic Web Project
2. Altere o Java Build Path para Alex_on_flex_java/WebContent/WEB-INF/classes
3. É necessário configurar o projeto como sendo um projeto do Tomcat
4. Crie a classe HelloWorld:
e deixe seu código parecido com o código abaixo:
package com.amf; public class HelloWorld { public String helloWorld(String nm_usuario){ return "Bem vindo " + nm_usuario; } }
5. Extraia o conteúdo do arquivo compactado do blazeds e depois extraia também os arquivos em blazeds.war (você pode utilizar o winrar)
Copie a pasta WEB-INF e cole em WebContent
6. Em WebContent> WEB-INF> flex altere o arquivo remoting-config.xml
Adicionando o código de referência a classe HelloWorld:
<!-- == Declaração da Classe com.amf.HelloWorld == --> <destination> <properties> <source>com.amf.HelloWorld</source> </properties> </destination> <!-- ============================================= -->
7. Crie um novo projeto Flex em File> New> Flex Project.
8. Altere o Flex Build Path da seguinte forma:
Output folder: C:\”Caminho do Tomcat”\webapps\alex_on_flex_flex
Output folder URL: http://localhost:”porta do tomcat”/alex_on_flex_flex
9. Renomeie o arquivo alex_on_flex_flex.mxml para index.mxml
10. Deixe o código do index.mxml como abaixo:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:RemoteObject destination="service_helloWorld" id="service_helloWorld" showBusyCursor="true" fault="Alert.show(event.toString());"> <mx:channelSet> <mx:ChannelSet> <mx:channels> <mx:AMFChannel id="myAmf" uri="/FlexJava/messagebroker/amf"/> </mx:channels> </mx:ChannelSet> </mx:channelSet> <mx:method name="helloWorld" result="resultHelloWorld(event)" fault="Alert.show(event.toString())"/> </mx:RemoteObject> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.rpc.events.ResultEvent; public function resultHelloWorld(re:ResultEvent):void{ Alert.show(re.result.toString(),'Alerta'); } ]]> </mx:Script> <mx:Label x="420.5" y="102" text="Seu Nome:" fontSize="16" fontWeight="bold"/> <mx:TextInput x="528.5" y="100" fontSize="16" width="219" id="txtUsuario"/> <mx:Button x="543.5" y="154" label="Enviar" fontSize="16" click="service_helloWorld.helloWorld(txtUsuario.text);"/> </mx:Application>
11. Clique com o botão direito do mouse sobre o projeto Java e envie para o tomcat em Tomcat Project> Exports to the WAR file sets in Project properties e em seguida reinicie o Tomcat.
12. Acesse http://localhost:9090/alex_on_flex_flex/ e veja a mágica acontecer.
Espero que tenham curtido.
Até o próximo.