Server-side Development Environment

From EsWiki

Jump to: navigation, search

Contents

Overview

To develop a server extension for ElectroServer usually means Java, although ActionScript will also work. This article explains how to set up your development environment so that you have all of the necessary classes to work with.

Java

IDE (Code Editor)

It is suggested that you use an IDE that has a language-aware editor and refactoring tools, such as NetBeans.

NetBeans Project

In NetBeans all your server side work will be encapsulated in a NetBeans Project. To get started:

  • Create a new NetBeans Project.
    1. Go to File -> New Project -> Java -> Java Application
      • (You can use an existing Ant Script if you have one you like to use)
    2. Hit next
    3. Place the project where you want, and give it a name
    4. Hit Finish
  • We also need to add ElectroServer4.jar as a library the project accesses.
    1. Under the Projects panel (default is top left of the screen), right click on libraries and select add JAR/folder.
    2. Find where you installed ElectroServer (likely in Program Files), then go into server/lib and select ElectroServer4.jar
    3. If you need other jar files add them at this time. For example, there are logging utilities in slf4j-api-1.4.3.jar.
    4. Hit Open

Customizing build.xml

If you use the default build.xml file, when you are ready to deploy your extension you will need to copy all your classes, the jars, and your Extension.xml file to the appropriate folder in ElectroServerInstallationFolder\server\extensions. If you are comfortable editing the build.xml file, here is a way to create an Ant target that will automate deployment. Let's assume that the name of your extension is SampleExtension.

Jar files

Create a folder and copy the jars needed into that folder.

property lines

Add two property lines near the top of the script.

    <property name="lib" value="...''path to the jar files''..." />
    <property name="deploypath" value ="''ElectroServerInstallationFolder''\server\extensions\SampleExtension" />

Change the italicized section to point to the location of your own installation of ElectroServer4, and the folder for your jar files.

clean target

Add the following line to the clean target:

        <delete dir="${deploypath}"/>

deploy target

Add the following Ant target to build.xml:

    <target name="deploy" depends="clean,build">
        <copy todir="${deploypath}" file="''pathToExtensionXML''/Extension.xml" />
        <copy todir="${deploypath}/lib">
            <fileset dir="${lib}" />
        </copy>
        <copy todir="${deploypath}/classes">
            <fileset dir="${build}" />
        </copy>
    </target>

Change the italicized section to point to the location of your Extension.xml file.

Use the deploy target

Add the deploy Ant target to your project's properties, in the Build and Run section. It will automatically clean and build before copying the needed files.

Example Ant Build Script (build.xml)

Here is a sample build script that you could use, which is a bit more complicated than the one described above.

<project name="SampleExtension" default="buildAll" basedir=".">
 
    <property name="build" value="build" />
    <property name="dist.jar" value="dist/jar" />
    <property name="dist.ext" value="dist/ext/SampleExtension" />
    <property name="src" value="src" />
    <property name="resources" value="test/resources" />
    <property name="lib" value="lib" />
    <property name="testpath" value="C:/ElectroServer_4_0_6/server/extensions/SampleExtension" />
 
    <target name="clean">
        <delete dir="${build}"/>
        <delete dir="${dist.jar}"/>
        <delete dir="${dist.ext}"/>
    </target>
 
    <target name="prep">
        <!-- Create the destination directory -->
        <mkdir dir="${dist.jar}" />
        <mkdir dir="${dist.ext}" />
        <mkdir dir="${build}" />
    </target>
 
    <target name="compile" depends="clean, prep">
        <javac destdir="${build}" deprecation="on" debug="on" target="1.5">
            <compilerarg line="-Xlint:unchecked" />
            <src path="${src}" />
            <classpath>
                <fileset dir="${lib}">
                    <include name="*.jar"/>
                    <include name="*.zip"/>
                </fileset>
            </classpath>
        </javac>
    </target>
 
    <target name="build" depends="compile">
        <jar jarfile="${dist.jar}/SampleExtension.jar">
            <fileset dir="${build}" />
        </jar>
    </target>
 
    <target name="deploy" depends="build">
        <copy todir="${dist.ext}">
            <fileset dir="${resources}" />
        </copy>
        <copy todir="${dist.ext}/lib">
            <fileset dir="${lib}" />
        </copy>
        <delete file="${dist.ext}/lib/ElectroServer4.jar" />
        <copy todir="${dist.ext}/lib" file="${dist.jar}/MyExtension.jar" />
    </target>
 
    <target name="test" depends="deploy">
        <delete dir="${testpath}"/>
        <copy todir="${testpath}">
            <fileset dir="${dist.ext}" />
        </copy>
    </target>
 
</project>

Customizations before use

Make the following customizations to the above sample build script:

  • Replace "SampleExtension" by the name of your extension (several places)
  • In the "src" property line, change the value to the relative path to your source code.
  • In the "resources" property line, change the value to the relative path to your Extension.xml file. Note: this script deletes the extension before copying in the new version, so keep your official copy of Extension.xml in the same project as your source code, not just in the ES4's server/extensions folder.
  • In the "lib" property line, change the value to the relative path to any jars you need (which should all be in the same folder)
  • In the "testpath" property line, change the value to the path to where you want the extension to be. If you have a local ES4 for testing it, then this will be to that ES4's server/extensions folder, with an appropriate name for the extension.

Targets

  • Clean : This does the relatively simple task of cleaning out the directories where the source will be compiled, and where it will be deployed, namely the ElectroServer extensions folder.
  • Compile : This is the command tells Java to compile the source to the build folder
  • Build : This will likely be a default target for your Java IDE, and it compiles and creates a jar file.
  • Deploy : Clean, Compile, Build, then create the extension in "dist/ext/SampleExtension" for easy copying to a remote ES4.
  • Test : Clean, Compile, Build, Deploy, then copy the extension to the local ES4 so all you need do is restart the ES4 to test it.

ActionScript

IDE (Code Editor)

It is suggested you use a tool that has auto-complete. FlashDevelop is a tool that has this capability, and can work together with the Flash IDE or the Flex compiler. (Though it does not need to be compiled for server side, it is just interpreted).

Finished!

Alright you've got your Environment configured. From here, you'll want to get your hands dirty with a plugin. A good place to start is the Server Side Tutorials like Hello World.

Personal tools
download