Tutorials:TomcatGuideCreateNewApps
From Red5Tutorials
Contents |
Develop & Deploy RED5 Applications in WAR for J2EE webcontainers(TOMCAT, …):
The following guide is made by Muthu Kumaran and published with his permission. Original URL: http://muthuar.aboutus.vg/Develop.htm
Introduction:
In this tutorial, we will just have a simple look in How to create Applications for containers… This tutorial explains How to compile the RED5 source into WAR and insert your own code to make the application flexible for the development in J2EE web servers .
Pre-requisites:
Following are the prerequisites for our mission(!) to be accomplished… 1. JDK 1.5 2. Apache Ant 3. The Web Archive source from RED5 ..
The JDK can be downloaded http://java.sun.com/j2se/1.5.0/download.html Apache Ant version 1.6.2 can be downloaded (http://archive.apache.org/dist/ant/binaries/ . The Red source can be downloaded from http://svn1.cvsdude.com/osflash/red5/java/war/trunk/... You may need eclipse to download the entire content
Getting the War source from eclipse:
Open the eclipse , Select File > Import > Other > Checkout Projects from SVN > Create a new Repository Location > URL http://svn1.cvsdude.com/osflash/red5/java/server/ > Select Cancel (As we are going to build using ANT)
Now Window > Open Perspective > Other > SVN Repository Exploring
A perspective window is opened with content http://svn1.cvsdude.com/osflash/red5/java/server/
Expand the branch you will see three child nodes 1. branches 2. tags 3. trunk
Right click on Node trunk & select Export
Select a directory, where do you need to keep the source. After the progress is over, switch to next step...
Building a web context (Virtual directory):
Open the source directory on your local computer {src dir}/trunk/www/WEB-INF. Now we are going to create a scope, I am going to name it samplescope. Now open a text editor and type the below content.
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:lang="http://www.springframework.org/schema/lang" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd"> <-- samplescope --> <bean id="samplescope.context" class="org.red5.server.Context" autowire="byType" /> <bean id="samplescope.scope" class="org.red5.server.WebScope" init-method="register"> <property name="server" ref="red5.server" /> <property name="parent" ref="global.scope" /> <property name="context" ref="samplescope.context" /> <property name="handler" ref="samplescope.handler" /> <property name="contextPath" value="/samplescope" /> <property name="virtualHosts" value="*,localhost, localhost:5080, 127.0.0.1:5080" /> </bean> <bean id="samplescope.handler" class="my.first.Application" /> </beans>
Save this content in the file "samplescope-context.xml" under the WEB-INF folder. The first bean is to define the context, next bean is to define the scope of the context, and the third denotes the handler for the context
Starting a simple Application:
We are going to create the Handler(application) now…
Goto {src-dir} \ trunk \ src \ { create the src files here}
As we have mentioned my.first.Application Create directories my \ first under src..
Create a java file named Application.java and place it under {src-dir} \ trunk \ src \ my \ first \ Application.java
package my.first;
import org.red5.server.adapter.ApplicationAdapter;
public class Application extends ApplicationAdapter {
public String getmyName(){
return "I don’t Know";
}
public String Congratulate(String b){
return "Alka " + b;
}
// Add as many functions as you need...
}
Building the source:
Make sure Path variables are pointing to the bin directories of Jdk & ANT installations.. Now open build.xml (present in {src-dir} \ trunk \ build.xml..
Create a property tag
<property name="build.compiler" value="javac"/>
and insert under <!-- project properties -->
save build.xml
In command prompt either in win or linux
Goto the directory…
{src-dir} \ trunk
enter ant webwar and hit the enter key
don’t worry about minor warnings, verify at last red5.war is finished....
If yes...then fine... if not send a mail to red5 ...
The war file will be present in {src-dir} \ trunk \ dist \ red5.war
Deploying WAR file in Tomcat..:
Open the Tomcat manager... usually will be
http://localhost:8080/manager/html
it will prompts for admin username & password , provide it….
And now under a table "WAR file to upload" upload the newly build war file...
...That’s it , Our WAR file has been deployed in Tomcat usually deployed with the name of the WAR file....
So it can be accessed via http://localhost:8080/red5
If you have problem in accessing tomcat manager ..
Download the Administration Web Application: of tomcat from http://tomcat.apache.org/download-55.cgi it is usually a zip copy consists of two folders ..
conf & server..
Stop your Tomcat service and replace the two folders in your Tomcat installation directory.. and start service again... and try to deploy the WAR file..
Simple client:
Open flash IDE , use the below code to invoke the functions
nc = new NetConnection();
nc.connect("rtmp://localhost/samplescope");
nc.onStatus = function(info) {
trace("Level: " + info.level + " Code: " + info.code );
}
nc.onResult = function(obj) {
trace("The result is " + obj);
}
nc.call("Congratulate", nc, "Me");
The result will be "Alka Me"
Reference:
1. http://www.joachim-bauch.de/tutorials/red5/HOWTO-NewApplications.txt
2. Google which pointed out more forums & topics
3. The contributors of RED5


