Java Consolidated Flex

Source: Internet
Author: User
Tags cdata tomcat server
Java+flex Project Integration

Java+flex 2010-12-20 16:11:12 Read 59 Comments 0 Font Size: biginSmall subscriptionsFirst: Java Engineering and flex engineering independence This is also the way many people use it. Flex programmers and Java programmers work independently of each other. Below is a description of the following. One, the need for software Myeclipes + Tomcat6.0 + Flex Builder3 + blazeds, online to download themselves. Second, configure the server side (Myeclipes + tomcat6.0 + blazeds) 1, the first blazeds compression packet decompression open, find Blazeds.war decompression, get Meta-inf folder and Web-inf folder. 2, open myeclipes, configure Tomcat server: Window->preferences->myeclipes->application server->tomcat->tomcat 6. X Configure Tomcat home directory for Tomcat installation path, and select Tomcat server->enable. 3, Next, create a Web project in MyEclipse, project name Peace. 4, then the first step to extract the Blazeds.war two folders pasted under the Peace project under the Webroot folder, the Override Prompt box appears, select Yes to all. 5, the following in the engineering of the SRC directory to write a Java class (package name Com.nankyrei.service, class name HelloWorld): Package Com.nankyrei.service public class HelloWorld {public String Gethello () {return ' Hello World ';}} 6, the Java class has been written, the following to declare this class in Remoting-config.xml (Bold character 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 then start Tomcat. Third, create flex Client 1, a new Flex project, named Flex_peace, select Application Server TYPE:J2EE. 2. This step is very important, click Next to set up 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. After filling in these three items, you need to click on the "Validate Configuration" button for configuration verification (this allows Tomcat to be turned on). Click Finish when the verification is complete. 3, the final writing 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 (), "failure");
}
]]>
</mx:Script>

<!--destination property values are consistent with the destination ID in 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, run Flex application, right click Flex_peace.mxml->run as->flex application can, ( Tomcat must remain running during periodSecond: Flex Engineering add Java elements
1, switch to Flex view, New Flex project, as shown below



Description: Java source folder is your own Java business source storage root directory, in FB3, LCDs
The project is designed to mix Java EE projects with FLEXLCDS projects.

Of course, if you do not choose to combined two together, then the trouble: or you can create a separate
Flex project, and this project writes only Java code. Or you can build a Java-EE project, and this

Because we are going to combine Java and Flex, the
In the server selection we choose the Java EE

To store the Java class source files, our purpose
Is that Flex and Java in a project, the
With our choice here,
Project to write only Flex code, but finally to put the Java compiled class file into the project under the
The webroot/web-inf/classes directory. That is, anyway, when the last release, the Java-compiled class
The file must be together with the project that the LCDs deploys.
2, click Next, configure the Java server, the following figure



Description: Target runtime is actually useless (later I deleted the corresponding information in the configuration file and
No problem), but cannot continue without designation, if the <none> is shown here then create a new
Tomcat's runtime, simply specify the Tomcat installation directory.

The content folder is actually the final compiled container directory, so BlazeDS's Blazeds.war
The file will be published to the Flex directory under Web-inf in the directory. Also because the tutorial is using
MyEclipse, his default is to release the contents of the WebRoot, in order to automate, so this is changed to
WebRoot (This is also the custom of Java development)

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

Compilation options Specify how the Flex file is compiled, and select the recommended flexbuilder in the
Although the development time is time-consuming, but after the release does not occupy the server's compile processing time, the
It's good for users.

Output folder refers to the path of files stored in a Flex-compiled SWF and HTML file, which is changed to
WebRoot, it means that you can publish to the root directory. Of course, you can set your own according to your needs and habits.
To place other paths

Because we use the blazeds, the
To set the BlazeDS road here.
Diameter
Here we can customize the output path,
In general, set to the root directory
WebRoot on it.
3, click Next, using the default configuration can be, click Complete, the project was established to complete. The figure below is the work
directory structure of the process


4, let it become a Web project by MyEclipse release it


of the Flex file
SOURCE folder
Java Source Files
Clip
Automatically generated by
Flex's configuration
File
Flex Post compiled
of the file. We send
The cloth is under the root directory


Click Finish, now our project icon has become a Java EE Web project, which means that you can


Be careful, don't order too fast.
Check it out so it doesn't cover blazeds.
Create Web.xml use MyEclipse to publish it or add more containers, such as Hibernate, spring, etc.

5. After the project is built, you can make more settings by right-clicking the-> property.



6, such a Flex+java project will be completed.
7, the preparation of examples, testing in the introduction of the third way after the unified introduction.

Third: Add Flex by Web project reverse, i.e. Java+flex
1, first set up a Web project: Flexweb. Slightly
2, to Flexweb Engineering to manually add the elements of flex needed.
1 First blazeds the required jar files to the project's Lib directory. The flex that you built above
The project's lib jar file is copied to the Lib directory under the project.
2) Then add the configuration file that Flex blazeds needs. Create a new text named Flex under Web-inf
folder, and then copy the Firstflex that we created above to the file in the four XML file
Clamp down.
3 Finally, modify the Web.xml file, add Flex configuration. Practice a simple put it on top we're new
Of the Flex Engineering Web.xml part of the code is copied over.

(Note: This will be an error, you can put

<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, release the project to Tomcat, and start Tomcat. (Note: Be sure to start Tomcat, because in the back
In the setup, it wants to verify the project path)
4, and then the project on the right button? Flex Project Nature? ADD Flex Project Nature



5, the completion of the setup, you will find that the Web project directory structure has changed, as shown below.
We found that the directory structure of the project built in this form and the second method are slightly different, Flex's
Mxml files are placed in the SRC folder by default and share a directory with Java files. And not like the last
The project automatically compiles the files that are available to run.




Configuring the server Path
Configure the correct display
It is recommended that you do not modify the configuration

6, if you are not satisfied with this directory structure, but also want to let flex files in the Flex_src directory, don't worry,
We can set it by right-clicking the property. The following figure



Here you can reset your flex source folder and output directory
7, configure the Flex default SDK. This configuration is complete, not yet, the program may not run normally, but also need
Configure the SDK that he uses. The following figure



8, right away, let's 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, really good ~ ~ ~ ~ ~ ~)");
Return "Hello" +name;
}
}
2 to flex configure this object to invoke, modify Web-inf/flex under Remoting-config.xml
Join:
<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, run Flexweb.mxml.
The third way, when you are finished compiling, 404 exceptions are found to access the Web page. The specific reasons are unknown. But it will still compile the
A SWF file, you can access this SWF. The second way is to compile an HTML file. A visit will come out
Now click on the interface:
Enter DFDFF, then output Hello DFDFF. Describes the success of invoking a Java class. I don't believe we can look at Java.
Class is printed on the console.


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

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

Solve:

The 11th line of 404 anomalies, I compare the second and the third kind of leakage.


This folder, so the solution: put the Leaky folder whole from a second copy to the project, refresh, be sure to refresh to appear


This folder has these contents in order to be successful.

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.