Search code examples
javared5

Red5 + Java + Windows installation + ant compilation : it works, but why?


I'm totally new to both java and java Server worlds... But I've a good knowledge (17 years) of object-oriented programming. My question is :

Why do I have to call ant to make it work (see later, if you're not interested, skip my question ^_^ ) ?

Here's what I want : create a simple application that can do a videoconference (= the server receives one client video stream and dispatches it to X clients). I wanted it free (Adobe Server costs something like 10000 dollars). The only solution I found is Red5 (see there)

I've downloaded and installed the 0.7 version. Here are the steps I did to be able to compile successfully a java application for Red5 :

  1. download and install (Windows XP) the latest release (0.7)
  2. download & copy manually in the install folder some files that have been forgotten in the 0.7 installation (compare to the v0.6 release and guess which ones) (ivy.xml if I remember)
  3. go in the [Red5 path]\webapps folder. Copy / paste the tutorial folder.
  4. rename the folder to myapp.
  5. edit all the xml files in that folder, search the string tutorial and rename it to myapp
  6. here's what I did and it did not work : compile with javac :
    javac -classpath "[Red5 path]\red5.jar" -d "[Red5 path]\webapps\myapp\WEB-INF\classes" Application.java javac -classpath "[Red5 path]\red5.jar" -d "[Red5 path]\webapps\myapp\WEB-INF\classes" TestService.java
  7. Everything worked fine but once I launched the Flex client the answer from the server was "Invalid Application"
  8. After many tries I found that removing everything but that code made everything work :

    package myapp;
    
    import org.red5.server.adapter.ApplicationAdapter;
    import org.red5.server.api.IConnection;
    import org.red5.server.api.IScope;    
    
    /* myapp */
    public class Application extends ApplicationAdapter {
    
    
    public String sayHello(Object[] params){
        return "got : " + params[0].toString();
    }
    
    }

Then I then wanted to be able to trace.

  1. I wrote that code that was working in the Red5 examples :

    package myapp;

    import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.red5.server.adapter.ApplicationAdapter; import org.red5.server.api.IConnection; import org.red5.server.api.IScope;

    public class Application extends ApplicationAdapter {

    protected static Logger log = LoggerFactory.getLogger(Application.class);
    
    public String sayHello(Object[] params){
        log.info("I got your name: "+params[0].toString());
        return "I got your name: " + params[0].toString();
    }
    

    }

  2. After restarting Red5 server : I always got that response from the server: "Invalid application"

  3. Then I downloaded ant, unpacked it in the [Red5 path]
  4. I've created a new file [Red5 path]\webapps\myapp\WEB-INF\build.xml
  5. I've put that xml in it :
<project name="Projet myapp" default="compile" basedir=".">
    <target name="clean" description="Clean output directories">
    </target>
    <target name="compile" depends="clean">
        <javac srcdir="./src" destdir="./classes" source="1.6" classpath="C:\Program Files\Red5\red5.jar" >
        </javac>
    </target>
    <target name = "jar" depends ="compile">
        <echo message ="Creating jar..."/>
        <jar destfile="./lib/myapp.jar" basedir="./classes"/>
        <echo message ="Done."/>
    </target>
</project>
  1. Run a shell, then type :
    cd [Red5 path]\webapps\myapp\WEB-INF
    ......\apache-ant-1.7.1\bin\ant jar
  2. Everything works fine now !
  3. Here's the question !
  4. What I don't understand is :
    Why do I have to call ant to make it work ?

Solution

  • Ant will both compile the code (compile target) and build the jar file (target jar), which will be placed in lib folder. When you simply compile the code with javac, the jar file isn't generated.