May 25, 2021 Flex
This tutorial explains how to create an application war file and how to deploy it in the Apache Tomcat Websever root. /b10> If you understand this simple example, you will also be able to deploy complex Flex applications in the same steps.
Let's follow these steps to create a Flex application:
Steps | Describe |
---|---|
1 | As described in the Flex - Create Applications section, create a project called HelloWorld under package com.tutorialspoint.client. |
2 | Modify HelloWorld.mxml, as described below. /b10> Keep the rest of the file unchanged. |
3 | Compile and run the application to ensure that the business logic works as required. |
Follow these steps to create a published version of your Flex application and then deploy it to the tomcat server:
The first step is to create a release version using the Flash Builder IDE.
Use
the
options File and Export and Flash Builder and Release Build
Use the wizard window to select the project as HelloWorld, as shown below
Leave the other default values and click the Finish button. /b10> Flash Builder will now create a bin-release folder that contains the release version of the project.
Now that our release is ready, let's follow these steps to deploy the Flex application:
Steps | Describe |
---|---|
1 | Compress the contents of the application's bin-release folder as a HelloWorld.war file and deploy it in Apache Tomcat Webserver. |
2 | Start your Web application with the appropriate URL, as described in the last step below. |
The following is the contents of the modified mxml file table-bordered / com.tutorialspoint / HelloWorld.mxml.
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%" minWidth="500" minHeight="500" initialize="application_initializeHandler(event)"> <fx:Style source="/com/tutorialspoint/client/Style.css"/> <fx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.FlexEvent; protected function btnClickMe_clickHandler(event:MouseEvent):void { Alert.show("Hello World!"); } protected function application_initializeHandler(event:FlexEvent):void { lblHeader.text = "My Hello World Application"; } ]]> </fx:Script> <s:BorderContainer width="500" height="500" id="mainContainer" styleName="container"> <s:VGroup width="100%" height="100%" gap="50" horizontalAlign="center" verticalAlign="middle"> <s:Label id="lblHeader" fontSize="40" color="0x777777" styleName="heading"/> <s:Button label="Click Me!" id="btnClickMe" click="btnClickMe_clickHandler(event)" styleName="button" /> </s:VGroup> </s:BorderContainer> </s:Application>
When all the changes are ready, let's compile and run the application in
normal mode, as in the Flex -
Create Application
chapter.
If all goes well with your application, this will result in the following results:
]
Now that our applictaion is working properly, we're going to export it as a war file. Follow these steps:
Go to your project's bin-release directory, C:\workspace?HelloWorld?bin-release
Select all files . . . /b10> The folder in the bin-release directory.
Compress all selected files . . . /b10> A folder named HelloWorld .zip folder.
Rename HelloWorld .zip HelloWorld.war.
Stop the tomcat server.
Copy the HelloWorld.war file to the tomcat installation directory and webapps folder.
Start the tomcat server.
Look inside the webapps directory, which should have a folder created by HelloWorld.
HelloWorld.war has now been successfully deployed in the Tomcat Webserver root.
Enter the URL in your web browser: http:// localhost:8080 / HelloWorld / HelloWorld.html to launch the application
The server name (localhost) and port (8080) may vary depending on your tomcat configuration.