Java Consolidation Flex

Source: Internet
Author: User
Tags cdata

Java+flex Project Integration

Java+flex 2010-12-20 16:11:12 Read Reviews 0 size: big medium small Subscribe

the first type: Javaproject and Flexproject IndependentSuch a way is also very many people use the way. The Flex program Ape and Java program Ape work independently of each other. The following are described below: First, the need for software Myeclipes + Tomcat6.0 + Flex Builder3 + blazeds, online to download themselves. Second, configure the server side (Myeclipes + Tomcat6.0 + blazeds) 1, first unpack the BlazeDS compression package, in the Find Blazeds.war decompression open, get Meta-inf directory and Web-inf directory. 2. Open Myeclipes, configure Tomcat server: Window->preferences->myeclipes->application server->tomcat->tomcat 6. X Configure Tomcat home directory for the installation path for Tomcat, and select Tomcat server->enable at the same time. 3. Next, create a Web project,project name peace in MyEclipse. 4, then the first step decompression Blazeds.war obtained two directories pasted into the Webroot directory under the Peace project, the Override Prompt box appears, select Yes to all. 5, the following in the SRC folder of this project to write a Java class (package name Com.nankyrei.service, class name HelloWorld): Packages Com.nankyrei.servicepublic Class Helloworld{public String Gethello () {return "Hello world"; }}6, Java class is written, the following to declare this class in Remoting-config.xml (Bold part): &LT;?MXL version= "1.0" encoding= "UTF-8"? ><service id= " Remoting-service "class=" Flex.messaging.services.RemotingService "><adapters><adapter-definition id=" Java-object "class=" Flex.messaging.services.remoting.adapters.JavaAdapter "default=" true "/></adapters>
<default-channels><channel ref= "MY-AMF"/></default-channels><destination id= "HelloWorld" ><porperties><!--here to write the full path: Package name + class name--><source>com.nankyrei.service.helloworld</source> </porperties></destination></service>7, okay, done, now deploy this project to Tomcatzhong and start Tomcat. Third, create a flexclient1, a new Flex project, named Flex_peace, select Application Server TYPE:J2EE. 2. This step is important, click Next, set server location, where root folder is the peace project path that was just deployed in Tomcat. To maintain consistency, the name of the relative path in the root URL and the context root remains the same as the Web project name. When these three items are filled in, you need to click on the "Validate Configuration" button for configuration verification (this is where Tomcat is turned on). Click Finish when the verification is complete. 3. Last write Client (flex_peace.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.controls.Alert;
Import mx.rpc.events.ResultEvent;

Private Function Resulthandler (event:resultevent): void {
Alert.show (Event.result.toString (), "success");
}

Private Function Faulthandler (event:faultevent): void {
Alert.show (Event.fault.toString (), "failed");
}
]]>
</mx:Script>

<!--The destination property value is the same as the ID destination in the Remoting-config.xml-
<mx:remoteobject id= "RemoteObject"
destination= "HelloWorld"
result= "Resulthandler (event)"
fault= "Faulthandler (event)"/>

<mx:button label= "Send Message" click= "Remoteobject.gethello ()" x= "256.5" y= "197"/>
</mx:application>4, execute Flex application, right-click Flex_peace.mxml->run As->flex Application to During Tomcat must remain in execution state) Another: Flex Engineering adds Java elements
1. Switch to Flex view to create a new flex project, such as



Description: Java source folder is your own Java Business source code to store the root folders, in FB3, LCDS
The project is designed to mix Java EE projects with FLEXLCDS projects.

Of course if you do not choose combined Two together, then the trouble: either you create a separate
Flex project, and this project just writes Java code. Or build another j2eeproject to write Java code, and this

Since we are going to combine Java with Flex, the
On the server selection we chose the Java EE

To store the Java class source files, our purpose
Is that Flex and Java are in a project,
Take our choice here.
Project to write only Flex code, but finally the Java compiled class file is placed under this project
The Webroot/web-inf/classes folder. In any case, when it is finally published, the Java compiled class
The file must be together with the project that the LCDs deploys.
2. Click Next to configure J2eeserver, for example, to



Description: Target runtime is actually useless (later I deleted the corresponding information in the configuration file and
No problem), but not specified can not continue, assuming here is <none> then create a new
The runtime of Tomcat simply requires the installation folder of Tomcat to be specified.

The Content folder is actually the container folder that was finally compiled, so BlazeDS's Blazeds.war
The file will be published to the Flex folder under Web-inf in this folder. At the same time because the tutorial is used
MyEclipse, his default is to publish the contents of the WebRoot, in order to self-initiative, so this change to
WebRoot (This is also the custom of Java development)

The Flex WAR file refers to the path of the Flex.war files after the LCDs is installed, but here we use
is blazeds to replace LCDs, so here is the path of Blazeds.war.

Compilation options Specifies how the Flex file is compiled, selecting the recommended Flexbuilder
Although the development time is more time, but after the publication will not occupy the server's compilation processing time,
There are advantages for the user.

Output folder refers to the path where the Flex-compiled SWF and HTML files are stored, changed to
WebRoot, meaning that it can be published to the root folder. Of course, you can set your own according to your needs and habits.
The other path

Because of the blazeds we use, the
To set the BlazeDS road here.
Diameter
Here we can define the output path ourselves,
Under normal circumstances set to root folder
WebRoot will be able.
3, click Next, using the default configuration will be able, click Finish, the project is completed. For the work
folder structure of the process


4, let it become WebProject published by MyEclipse


of the Flex file
SOURCE folder
Java Source Files
Clip
Their own initiative to generate
Configuration of Flex
File
Flex Post-compilation announcement
The file. We send
Cloth under the root folder


Click Finish and now our Project icon has become the Java EE Web Project, which means that you can


Attention, do not point too fast, to put the
Check it out so that it doesn't cover the blazeds.
The Web. XML is created using MyEclipse to advertise it or to add many other containers, such as Hibernate, spring, etc.

5. After project is built, you can make many other settings by right-click Properties.



6, such a Flex+java project is established.
7, the preparation of samples, testing in the introduction of the third way after the unified introduction.

Third: by Web project Reverse adding Flex, which is Java+flex
1, first set up a webproject:flexweb. Slightly
2. Manually add the required elements of flex to Flexweb project.
1) First copy the jar files required by BlazeDS to the Lib folder of project. To be able to build that flex
The jar file under Project Lib is copied under the Lib folder under Project.
2) then add the required configuration file for Flex blazeds. Create a new text named Flex under Web-inf
folder, and then copy the four XML files that we created above the Firstflex to the file
Clamp down.
3) Finally, change the Web. xml file to increase the Flex configuration. Procedure a simple put up above us new
Part of the code for the Flexproject Web. XML is copied over.

(Note: This can be an error,

<web-app version= "2.4"
xmlns= "http://java.sun.com/xml/ns/j2ee"
Xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation= "http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">

Change to:<web-app>)


<context-param>
<param-name>flex.class.path</param-name>

<param-value>/web-inf/flex/hotfixes,/web-inf/flex/jars</param-val
Ue>
</context-param>

<!--Http Flex Session attribute and binding listener support--
<listener>

<listener-class>flex.messaging.HttpFlexSession</listener-class>
</listener>

<!--messagebroker Servlet---
<servlet>
<servlet-name>MessageBrokerServlet</servlet-name>
<display-name>MessageBrokerServlet</display-name>

<servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
<init-param>
<param-name>services.configuration.file</param-name>

<param-value>/WEB-INF/flex/services-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>MessageBrokerServlet</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
3. Publish the project to Tomcat and start Tomcat. (Note: Be sure to start Tomcat because in the back
setting, it verifies the path to project)
4. Then right-click on the project? Flex Project Nature? ADD Flex Project Nature



5, set up, you will find that the folder structure of WebProject has changed, for example.
We find that the folder structure of project created in this form is slightly different from the other method, and the Flex
The Mxml file is placed by default in the SRC folder, and a folder is shared with the Java file. And nothing like the last
Project to compile executable files on its own initiative.




Configure the server path
Configure the correct display
It is recommended not to change the configuration here

6, assume that you are not very comfortable with this folder structure, but also want to put the flex files in the Flex_src folder, don't worry,
We can set it by right-click property. For example with



Here you can set up your Flex source folder and output folder again
7. Configure the Flex Default SDK. After this configuration, not yet, the program may not be able to perform properly, but also need to
Configure the SDK that he uses. For example with



8, immediately finished, let us write a program to test it.
1) Create a new Java class: Hello.java
Package com;

public class Hello {
public string Hello (string name) {
SYSTEM.OUT.PRINTLN ("Flex calls me, it's good ~ ~ ~");
Return "Hello" +name;
}
}
2) Configure the object to be called for Flex, change Web-inf/flex under Remoting-config.xml
Increase:
<destination id= "Hello" >
<properties>
<source>
Com. Hello
</source>
</properties>
</destination>

3) Write a flex program
<?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://LOCALHOST:8080/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="/>
<mx:label text= "name" x= "y="/>
</mx:Application>
4) Restart Tomcat to execute flexweb.mxml.
The third method, after compiling, access to the page will appear 404 exceptions. Detailed reasons are unknown. But it will still compile the
A SWF file to access this SWF. And another way to compile an HTML file. Interview
Now the interface:
Enter DFDFF, then output Hello DFDFF. Describes the successful invocation of the Java class. Don't believe we can look at Java
Class is printed on the console.


Configuration success, Happy, O (∩_∩) o ... Ha ha.
If you use LCDs, you do not need to precompile, you can directly access the Mxml file, LCDs will dynamically compile the returned results.

Reprinted from: http://cache.baidu.com/c?m= 9f65cb4a8c8507ed4fece7631046893b4c4380147d8c8c4668d4e419ce3b4c413037bfa6663f405a8e906b6075a91f5fbdf43176610123b5999cc0169 bac925f75ce786a6459db0144dc4df19c0c32c050872a9ab86891adf142cbfd9680c85523dd22026df7f69c2c0403bb6ee71541f4d7ef5f652e07ca9b 2712ff&p=8b2a94039e8311a058ecc8601e56&user=baidu

Solve:

Countdown No. One Line of 404 exception, and I found a third leak against the other and the third kind.


This directory, so solve the method: The missing directory from another copy of the entire project, refresh, must be refreshed to appear


This directory has these contents, the talent is successful.


Java Consolidation Flex

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.